Array ( [0] => Array ( [0] => 15 [id] => 15 [list] => Array ( [0] => Array ( [0] => 16 [id] => 16 [list] => Array ( [0] => Array ( [0] => 18 [id] => 18 [list] => Array ( ) ) ) ) [1] => Array ( [0] => 19 [id] => 19 [list] => Array ( ) ) ) ) [1] => Array ( [0] => 20 [id] => 20 [list] => Array ( ) ) ) 相把这样的多维数组重新按照键名一样的组成一个新数组如下:Array( [0] => 15 [1] => 16 [2] => 18 [3] => 19 [4] => 20)键值得循序不一定要按小到大,主要是把多维数组重新组成这样的数组。键名一样的指的是:如键名都是[id]
<?php$old_arr = array(...);$new_arr = '';function dg($arr){ foreach($arr as $item){ is_array($item['list']) && dg(); $new_arr[] = $item['id']; }}// www.hi-docs.com/php/is_array.htmldg();?>思路大概是这样,自己改下
function getRes($arr){ static $result = array(); foreach ($arr as $k => $v) { if (!is_array($v)) { $result[$k][] = $v; }else{ getRes($v); } } return $result;}$a = getRes($array);按照键名分类,形成一个二维数组。