//静态变量是只存在于函数作用域中的变量,注释:执行后这种变量不会丢失(下次调用这个函数时,变量仍会记着原来的值)
function array_multi2single($array){
static $result_array=array();
foreach($array as $value){
if(is_array($value)){
array_multi2single($value);
}
else
$result_array[]=$value;
}
return $result_array;
}
$array=array("1"=>array("A","B","C",array("D","E")),"2"=>array("F","G","H","I"));
$array=array_multi2single($array);
foreach($array as $value){
echo "<h5>$value</h5>";
echo "<br>";
}
//采用数组引用来实现,这样比上一种要好哦
function array_multi2single($array,&$rs = array()){
foreach($array as $value){
if(is_array($value)){
array_multi2single($value, $rs);
}
else
$rs[]=$value;
}
}
$array=array("1"=>array("A","B","C",array("D","E")),"2"=>array("F","G","H","I"));
array_multi2single($array, $rs);
print_r($rs);