这是我的product
阵列 -
Array
(
[0] => Array
(
[0] => 'Product1'
[1] =>
[2] =>
[3] =>
[4] => 'Product2'
[5] =>
[6] =>
[7] => 'Product3'
[8] => 'Product4'
[9] => 'Product5'
)
)
这是category
产品的阵列 -
Array
(
[0] => Array
(
[0] => 'cat1'
[1] => 'cat2'
[2] => 'cat3'
[3] => 'cat4'
[4] => 'cat5'
[5] => 'cat6'
[6] => 'cat7'
[7] =>
[8] =>
[9] =>
)
)
需要这种格式的最终输出 -
Array
(
'Product1' => Array(
[0] => 'cat1',
[1] => 'cat2',
[2] => 'cat1',
[3] => 'cat4'
),
'Product2' => Array(
[0] => 'cat5',
[1] => 'cat6',
[2] => 'cat7'
),
'Product3' => Array(
[0] => 'No Cat'
),
'Product4' => Array(
[0] => 'No Cat'
),
'Product5' => Array(
[0] => 'No Cat',
)
)
我试过了,但这没有形成正确的输出——
$newarr = array();
foreach( $productData[0] as $arr1 )
{
if( $arr1 != '' )
{
foreach( $catData[0] as $catnames ){
$newarr[$arr1] = array($compnames);
}
}
}
echo "<pre>";print_r($newarr);