What are the methods for PHP to loop through an array
Editor to share with you what are the methods of PHP looping through the array, I hope you will get something after reading this article, let's discuss it together!
1. Foreach (): foreach () is the simplest and most efficient way to traverse the data in an array.
Colors = array ("red", "green", "blue", "yellow"); foreach ($colors as $value) {echo "The color is $value"
";} # output / * * The color is redThe color is greenThe color is blueThe color is yellow**/
For (): use the for statement to loop through the array, which must be an indexed array.
$colors = array ("red", "green", "blue", "yellow"); for ($iTun0; $I