PHP one-dimensional array loop traversal

怪我咯
Release: 2023-03-13 15:40:01
Original
1370 people have browsed it

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

<?php 
/* 
 * 数组的遍历 
 */ 
  $language = array("French",&#39;German&#39;,&#39;Russian&#39;,&#39;Chinese&#39;,&#39;Hindi&#39;,&#39;Quechu&#39;); 
  foreach ($language as $key => $value) { 
    echo $key.&#39;=&#39;.$value.&#39;<br />&#39;; 
  } 
?>
Copy after login

Traversing the associative array

<?php 
  /* 
   * 关联数组的遍历 
   */ 
   $userList = array(&#39;UserName&#39;=>&#39;Lilia&#39;,&#39;Gender&#39;=>&#39;female&#39;,&#39;Age&#39;=>&#39;23&#39;,&#39;School&#39;=>&#39;Peking University&#39;); 
   foreach ($userList as $key => $value)  
  { 
    echo $key.&#39;=&#39;.$value.&#39;<br />&#39;; 
   } 
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!