Home  >  Article  >  Backend Development  >  PHP one-dimensional array loop traversal

PHP one-dimensional array loop traversal

怪我咯
怪我咯Original
2017-07-11 16:47:421260browse

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:

foreachTraversing the array

 $value) { 
    echo $key.'='.$value.'
'; } ?>

Traversing the associative array

'Lilia','Gender'=>'female','Age'=>'23','School'=>'Peking University'); 
   foreach ($userList as $key => $value)  
  { 
    echo $key.'='.$value.'
'; } ?>

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn