我有一个关联数组:
Array (
[0] => Array ( [term_title] => black )
[1] => Array ( [color_quantity] => 2 )
[2] => Array ( [color_price] => 22 )
[3] => Array ( [term_title] => blue )
[4] => Array ( [color_quantity] => 3 )
[5] => Array ( [color_price] => 33 ))
如何将其更改为:
Array (
[0] => Array ( [term_title] => black, [color_quantity] => 2, [color_price] => 22 )
[1] => Array ( [term_title] => blue, [color_quantity] => 3, [color_price] => 33 ) )
我尝试以下代码:
$post = array();
for($i = 0; $i < 2; $i++){
foreach($feild_data as $data){
$post[$i][$data['name']] = $data['value'];
}
}
但是它重复最后一个索引两次。即
Array (
[0] => Array ( [term_title] => blue, [color_quantity] => 3, [color_price] => 33 )
[1] => Array ( [term_title] => blue, [color_quantity] => 3, [color_price] => 33 ) )
不确定name
和value
在$data['name']
和$data['value']
中来自何处,但是您可以使用array_chunk
将它们分成多个块并将它们分配给array_chunk
。
$posts