php计算多层数组
函数
function countarray($arr){
$count = 1;
$max = 0;
foreach ($arr as $key => $value) {
if(is_array($value)){
$ncount = count array($value);
if($ncount > $max){
$max = $ncount;
}
}
}
$count += $max;
return $count;
}
测试
$arr = array(
"web" => array(
"0" => array(
"value" => array(
"0" => "您好",
"1" => "你好",
"2" => array(
"0" => "您好",
"1" => "你好",
"2" => array(
"0" => "您好",
"1" => "你好",
"2" => "hello"
)
)
),
"key" => "Hello"
),
"1" => array(
"value" => array(
"0" => "hi",
"1" => "hh",
"2" => "hello"
),
"key" => "Hello Kitty"
),
"2" => array(
"value" => array(
"0" => "hello",
"1" => "test",
),
"key" => "Hello"
),
)
);
echo countarray($arr); // 6
本文作者:风雪,转载时请注明本文出处:https://www.fxnetw.com/60.html
共
0
条评论