In PHP, use foreach () to traverse a simple example of a two-dimensional array. PHP uses foreach () to traverse a simple example of a two-dimensional array. The first type of foreach two-dimensional array wants to traverse the whole two-dimensional array with foreach (): $ teamarray (lk, OK ); $ bookarray (using foreach () in lin PHP to traverse simple instances of two-dimensional arrays, foreach two-dimensional arrays
Type 1
I want to use foreach () to traverse the entire two-dimensional array:
$ Team = array ('LK ',' OK '); $ book = array ('Linux server configuration and management', $ team ); foreach ($ book as $ k => $ val) // for $ book each $ value (as) echo $ k. '=> '. $ val. '';
The output result is:
0 => linux server configuration and management
1 => Array
Of course, I actually want all the specific content, not the output array...
Therefore, add a judgment statement as follows:
$ Team = array ('LK ',' OK '); $ book = array ('Linux server configuration and management', $ team ); foreach ($ book as $ k => $ val) // meaning for $ book each $ value (as) if (is_array ($ val )) foreach ($ val as $ value) echo $ value. ''; else echo $ k. '=> '. $ val. '';
The output is:
0 => linux server configuration and management
Lk
OK
Echo"
"; Echo" php traversing two-dimensional arrays "; // $ team = array ('LK ',' OK '); // $ book = array ('Linux server configuration and management', $ team); $ arr = array ('name' => 'system configuration ', 'URL' => '? Action = config & do = config'), array ('name' => 'verification code configuration', 'URL' => '? Action = config & do = seccode'), array ('name' => 'template management', 'URL' => '? Action = config & do = tpl '), array ('name' => 'account management', 'URL' => '? Action = admin & do = list'), array ('name' => 'Add account', 'URL' => '? Action = admin & do = add'); foreach ($ arr as $ k => $ val) {echo "name :". $ val ["name"]. "/n ";}
The simple example of traversing a two-dimensional array using foreach () in PHP above is all the content shared by Xiaobian. I hope you can give us a reference and support for the house.
A simple example of traversing a two-dimensional array. The first type of the foreach two-dimensional array is to traverse the whole two-dimensional array using foreach (): $ team = array ('LK ',' OK '); $ book = array ('Lin...