: This article mainly introduces PHP code for traversing arrays. you can refer to these three methods for PHP tutorials. $ People = array ("Peter", "Joe", "Glenn", "Cleveland ");
$ People1 = array ("Peter", "Joe", "asd" => "Glenn", "Cleveland ");
// 7. list (variable 1, variable 2, variable 3); used together with each to traverse the array.
// The list function assigns values to a group of variables with elements in the array.
// This function is only used for the number index array, and it is assumed that the number index starts from 0.
List ($ a1, $ a2, $ a3) = $ people1; // assign the array people1 to list
Echo $ a1. $ a2. $ a3; // output the values in the list.
Echo"
";
// 6. each (array1); generates an array consisting of the key and key values of the elements pointed to by the current internal pointer of the array,
// Move the internal pointer forward.
Print_r (each ($ people ));
Print_r (each ($ people ));
Reset ($ people); // reset the pointer
// Give the key and value in people1 to list
While (list ($ key, $ val) = each ($ people1 ))
{
Echo "$ key => $ val
";
}
For ($ I = 0; $ I
Echo $ people [$ I]."
";
}
Foreach ($ people as $ v ){
Echo $ v ."
";
}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above introduces the PHP code for traversing arrays, three methods, including content, hope to be helpful to friends who are interested in PHP tutorials.