: This article mainly introduces common methods for php array traversal. For more information about PHP tutorials, see. 1. one-dimensional array traversal
Foreach ($ array as $ value) {echo $ value ;}
2. 2d array traversal
Foreach ($ array $ key => $ val) {echo $ key. '=>'. $ val ;}
3. multi-dimensional array traversal
Public static function multi_arr_foreach ($ arr) {static $ data; if (! Is_array ($ arr) {return $ data;} foreach ($ arr as $ key => $ val) {if (is_array ($ val) {self :: multi_arr_foreach ($ val);} else {$ data [] = $ val;} return $ data ;}However, I still see a very short writing method, which is not very understandable.
Function loop_array ($ arr) {$ value = is_array ($ arr )? Array_map ('loop _ array', $ arr): $ arr; return $ value ;}
The above describes the common methods of php array traversal, including the content, hope to be helpful to friends who are interested in PHP tutorials.