PHP two-dimensional join array Traversal method, php two-dimensional array
The foreach loop is used to traverse the two-dimensional index array, which is relatively faster and more efficient. The foreach loop is used by PHP to loop the array.
The instance is relatively simple. You just need to practice more and find out the program running logic.
<? Php $ arr = array (// defines the outer array "Beijing director" => array (1, 'gao mou', 'a company', 'beijing', '(010) 987654321 ', 'GM @ Linux.com'), // sub-array 1 "Shanghai manager" => array (2, 'loom', 'B', 'shanghai ', '(021) 123456789', 'lm @ apache.com '), // sub-array 2 "Tianjin owner" => array (3, 'fengmou', 'c company ', 'tianjin City ',' (022) 24680246 ', 'fm @ mysql.com'), // sub-array 3 "Chongqing owner" => array (4, 'shu mou ', 'd company ', 'chongqing', '(023) 13579135', 'sm @ php.com ') // subarray 4 ); foreach ($ arr as $ key => $ arr_item) {echo $ key; // obtain the array key echo "<pre>"; print_r ($ arr_ite M); // $ arr_item is the subarray echo "</pre>"; foreach ($ arr_item as $ value) {echo $ value. "==="; // array value }}?>
Summary:
1. When traversing two-dimensional joined arrays, The for loop may not be used.
2. $ key: extract the key of the $ arr array.
3. $ arr_item is a sub-array (sub-array 1, Sub-array 2 .....)