<?php $arr = array( array( array( array( array( 5,6,7 ) ) ), array( "test" => array(1,2,3) ) ), array(1, 2, 3) ); function arr_foreach ($arr) { static $data; if (!is_array ($arr)) { return $data; } foreach ($arr as $key => $val ) { if (is_array ($val)) { arr_foreach ($val); } else { $data[]=$val; } } return $data; } $result = arr_foreach($arr); var_dump($result); var_dump($arr);