<?php
function recursive_array($a)
{
foreach($a as $value)
{
$value = recursive_array($value);
}
if (!isset($max))
{
$max = $value;
}else{
$max = $vlaue > $max ? $value : $max;
}
return $max;
}
$arr = array(57,array(3,35),array(34545,232,123,435));
$max = recursive_array($arr);
echo $max;
本例中展示的函數能夠找到數組裡的最大值,其功能與PHP內置的max()函數類似,但這個遞歸函數能夠深入到數組內部。注意到其中使用了is_array()函數來判斷數組中的