0x01
三维数组中,选取其中的数据,重新组合 摘自SF上 记录下
Code:
-------
function combineDika($data) { $result = array(); foreach (array_shift($data) as $k=>$item) { $result[] = array($k=>$item); } foreach ($data as $k => $v) { $result2 = []; foreach ($result as $k1=>$item1) { foreach ($v as $k2=>$item2) { $temp = $item1; $temp[$k2] = $item2; $result2[] = $temp; } } $result = $result2; } return $result; } $skuattr = Array ( ‘7‘ => Array ( ‘6‘ => ‘22x33‘, ‘9‘ => ‘44x55‘, ), ‘8‘ => Array ( ‘12‘ => ‘大小号‘ ), ‘9‘ => Array ( ‘8‘ => ‘金属质‘, ‘13‘ => ‘塑料‘, ), ‘16‘ => Array ( ‘14‘ => ‘圆形‘ ) ); $a = combineDika($skuattr); print_r($a);
0x02
三维数组 转化为二维数组
<?php $array = array(‘0‘=>array(‘1‘=>‘a‘,‘2‘=>‘b‘), ‘1‘=>array(‘3‘=>‘c‘,‘4‘=>‘d‘), ); foreach ($array as $key=>$value){ foreach($value as $k=>$v){ $data[] =$v; } } print_r($data); ?>
时间: 2024-10-25 19:21:27