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

PHP one-dimensional array loop traversal implementation code

不言
不言Original
2018-04-26 14:01:541180browse

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",&#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;; 
  } 
?>


##association Array traversal


<?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;; 
   } 
?>


This is a very simple example, used every time It is very troublesome to GG every time, so just record it and extract it directly when using it.

Related recommendations:

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!

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