No code, no idea, you can.
For example
$earth = Array (
'asia'=>array( 'china'=>array( 'beijing', 'shanghai', 'tianjin', 'hangzhou' ), 'japan'=>array( 'tokyo', 'hokkaido', 'nagasaki' )),'europe'=>array( 'france'=>array( 'paris', 'lyon' ), 'spain'=>array( 'madrid', 'barcelona', 'sevilla' )),'australia'=>array( 'australia'=>array( 'sydney', 'melbourne' ))
);
Back to 3,5,14
Reply content:
No code, no idea, you can.
For example
$earth = Array (
'asia'=>array( 'china'=>array( 'beijing', 'shanghai', 'tianjin', 'hangzhou' ), 'japan'=>array( 'tokyo', 'hokkaido', 'nagasaki' )),'europe'=>array( 'france'=>array( 'paris', 'lyon' ), 'spain'=>array( 'madrid', 'barcelona', 'sevilla' )),'australia'=>array( 'australia'=>array( 'sydney', 'melbourne' ))
);
Back to 3,5,14
I think you're going to have to do this sort of statistic, only in a recursive way.
// $array:要统计的数组,$i为第几维,$count维上层统计function count_array($array,$i=1,$count = array()) { $n = 0; if(isset($count[$i])) { $n = $count[$i]; } $count[$i] = count($array) + $n; $i += 1; foreach($array as $item) { if(is_array($item)) { $count = sp_arr($item,$i,$count); } } return $count;}$array = array( 'a' => array( 'b' => 'c', 'd' => 'e', 'f' => 'g', ), 'h' => array( 'i' => array( 'j' => 'k', 'l' => 'm', 'n' => array( 'o' => 'p', 'q' => 'r' ) ) ));$count = count_array($array);var_dump($count); // result:/** *array (size=4) * 1 => int 2 * 2 => int 4 * 3 => int 3 * 4 => int 2 */
Well, I write a loop (optimized, self-optimizing, because I'm not very familiar with PHP)
In short, a breadth-first search (a slightly optimized queue, if changed to a stack, is the depth first)
function count_array($array) { $count = array(); $level = 0; $tfifo = $array; do{ $fifo = $tfifo; $tfifo = array(); $count[$level] = 0; foreach($fifo as $item){ $count[$level]++; if(is_array($item)) { foreach($item as $subitem){ $tfifo[] = $subitem; } } } $level++; }while(count($tfifo)>0); return $count;}
ARR{X}{Y}[Z]
The third dimension of the number of elements is not arr{x}{y}.length it?
And so on?
Or do I have a mistake in understanding your problem?
With the square brackets just ahead of the not out,,,
$num = array() ; function get_num($fat,$num){ $num[] = count($fat) ; $sun = array() ; foreach ($fat as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $sun[] = $v ; } } } if ($sun) { return get_num($sun,$num) ; } return $num ;}// var_dump(get_num($arr,$fat)) ;大神解答,发出来给大家分享一下