Home >Backend Development >PHP Tutorial >PHP one-dimensional array loop traversal implementation code
The content of this article is about the loop traversal implementation code of one-dimensional array in PHP. It has certain reference value. Now I share it with you. Friends in need can refer to it.
A simple PHP loop An example of 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 example of PHP looping a one-dimensional array, first Converting a string into an array according to certain rules, and then traversing the output, is actually a very simple method. Because I recently made a two-dimensional array structure diagram that gave me a headache, so I couldn’t remember how to do it for a while. The traversal output is performed. 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 />'; } ?>
<?php /* * 关联数组的遍历 */ $userList = array('UserName'=>'Lilia','Gender'=>'female','Age'=>'23','School'=>'Peking University'); foreach ($userList as $key => $value) { echo $key.'='.$value.'<br />'; } ?>
Examples of conversion between one-dimensional arrays and two-dimensional arrays in PHP
Comparison of one-dimensional array traversal methods in PHP analyze
The above is the detailed content of PHP one-dimensional array loop traversal implementation code. For more information, please follow other related articles on the PHP Chinese website!