Home >Backend Development >PHP Tutorial >Comparative analysis of PHP one-dimensional array traversal methods
Code description: Statement a $arr=array('a'=>'abc','b'=>123,'c'=>true); Initialize $arr to get the numeric index array, output: , , , abc, 123, 1, a-abc, b-123, c-1, a-abc, b-123, c-1, a-abc, b-123, c-1, use statement b $arr=range('a','d'); to initialize $arr to get the associative array, output: a, b, c, d, a, b, c, d, 0-a, 1-b, 2-c, 3-d, 0-a, 1-b, 2-c, 3-d, 0-a, 1-b, 2-c, 3-d, The for loop only has limited numeric indexes; after the for and foreach traversal, the data does not need to be reset() to be available for the next traversal, while the each method does.The above is the entire content of today’s PHP tutorial. I hope it will help you master the method of PHP array traversal. Programmer’s Home, I wish you all the best in your study and progress. |