array("F","G","H","I"));$array=array_multi2single($array);echo "测试结果:";foreach($a">
当前位置:Gxlcms > PHP教程 > php自定义函数:递归把多维数组转为一维数组

php自定义函数:递归把多维数组转为一维数组

时间:2021-07-01 10:21:17 帮助过:18人阅读

  1. function array_multi2single($array)

  2. {
  3. static $result_array=array();
  4. foreach($array as $value)
  5. {
  6. if(is_array($value))
  7. {
  8. array_multi2single($value);
  9. }
  10. else
  11. $result_array[]=$value;
  12. }
  13. return $result_array;
  14. }

  15. //测试

  16. $array=array("1"=>array("A","B","C",array("D","E")),"2"=>array("F","G","H","I"));
  17. $array=array_multi2single($array);
  18. echo "

    测试结果:

    ";
  19. foreach($array as $value)
  20. {
  21. echo "
    $value
    ";
  22. echo "
    ";
  23. }
  24. ?>

人气教程排行