PHP将二维数组转为一维数组的实例代码分享

正文:
这是我之前写的一个原创PHP函数,在其他网站上面已经发过了,但是今天突然发现自己网站都还没发过呢,所以就给自己网站补一篇吧,当然,我这个函数不是所有情况都支持转换的,只能固定的一种格式才行,例如:
Array ( [0] => Array ( [aaa] => 1 ) [1] => Array ( [ddd] => 2) [2] => Array ( [ccc] => 2) )
上面这种数组格式才支持转换为一维数组,转换完成之后:
Array ( [aaa] => 1 [ddd] => 8655 [ccc] => 666 )
如果这个函数对你有帮助,大家自己可以拿去研究一下,我这个写的也并不是很完美,还有很多地方可以优化的。
function szzh($shuzu){
$shu = count($shuzu);
$bianlianggeshu=0;
for($i = 1; $i < $shu+1; $i++) {
${"shuzu$i"} = shuzuay();
$bianlianggeshu++;
}
for($i=1; $i<$shu+1; $i++){
if(${"shuzu$i"} == null){
${"shuzu$i"} = $shuzu[$i-1];
}
}
$ii=2;
for($i = 1; $i < ($bianlianggeshu+1)/2; $i++) {
$shuzu = shuzuay_merge(${"shuzu$i"} , ${"shuzu$ii"});
$ii++;
$shuzu = shuzuay_merge($shuzu , ${"shuzu$ii"});
}
}
$shuzu = zhuanhuan(需要传入的数组变量);
print_r($shuzu);
本文结束
 
       烟云博客
烟云博客                 
    
    

