Home >Backend Development >PHP Tutorial >PHP one-dimensional array loop traversal implementation method
A simple example of PHP looping a one-dimensional array, first convert the string into an array according to certain rules, and then traverse the output. It is actually a very simple method
A simple PHP An example of looping a one-dimensional array is to first convert the string into an array according to certain rules, and then traverse the output. It is actually a very simple method, because a two-dimensional array structure diagram I recently made was a headache, so I can't remember how to perform traversal output for a while. The simple example code is as follows:
foreach traverses the array
<?php /* * 数组的遍历 */ $language = array("French",'German','Russian','Chinese','Hindi','Quechu'); foreach ($language as $key => $value) { echo $key.'='.$value.'<br />'; } ?>
Traverses the associative array
<?php /* * 关联数组的遍历 */ $userList = array('UserName'=>'Lilia','Gender'=>'female','Age'=>'23','School'=>'Peking University'); foreach ($userList as $key => $value) { echo $key.'='.$value.'<br />'; } ?>
The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
How to automatically load classes in PHP
PHP Two-dimensional array deduplication or statistics based on a certain field
The above is the detailed content of PHP one-dimensional array loop traversal implementation method. For more information, please follow other related articles on the PHP Chinese website!