You can use subscript variables in the program, which means that the entirety of these variables is an array, and the data type of each variable in the array is the same. When each element in the array has only one subscript, such an array is called One-dimensional array.
One-dimensional array is a single-structured array composed of numbers arranged in a simple sorting structure. One-dimensional arrays are the most basic arrays in computer programs. Two-dimensional and multidimensional arrays can be regarded as generated by multiple superpositions of one-dimensional arrays.
A simple example of PHP looping a one-dimensional array. First, the string is converted into an array according to certain rules, and then traversed and output. It is actually a very simple method, because of a recent Two-dimensional arrayThe structure diagram gave me a headache, so I couldn’t remember how to traverse the output for a while. The simple example code is as follows:
<?php /* * 数组的遍历 */ $language = array("French",'German','Russian','Chinese','Hindi','Quechu'); foreach ($language as $key => $value) { echo $key.'='.$value.'<br />'; } ?>
Traversing 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 detailed content of PHP one-dimensional array loop traversal. For more information, please follow other related articles on the PHP Chinese website!