我有三个这样的数组:
array1(
0=>'title 1',
1=>'title 2'
)
array2(
0=>'description 1',
1=>'description 2'
)
array3(
0=>'price 1',
1=>'price 2'
)
有一个php函数可以按这样的键对数组值进行分组吗?
array(
0=>array(title 1, description 1, price 1),
1=>array(title 2, description 2, price 2),
)
答案 0 :(得分:6)
array_map(null, $array1, $array2, $array3)
答案 1 :(得分:0)
试试这段代码。
$array3 = array();
foreach ( $array1 as $key => $val ) {
if ( !isset($array3[$val]) )
$array3[$val] = array();
$array3[$val][] = $array2[$key];
}
print_r($array3);
答案 2 :(得分:0)
$pool =array();
foreach ( array_map(null, $array1, $array2, $array3) as $key => $value) {
$pool[$key] = implode(", ", $value);
}
print_r($pool);
Array
(
[0] => title 1, description 1, price 1
[1] => title 2, description 2, price 2
)