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); ?>
数组转换重组数据时,可采用foreach循环外,加$i的形式,
$array = array('0'=>array('0'=>'a','1'=>'b'),'1=>array('0'=>1));
$data = array();
$i=1;
foreach($array as $k=>$v){
$data1=$v['0'];
//操作
foreach($v as $key=>$value){
$data2[$i] = $value;
$i++;
}
}
print_r($data2);