Home >Backend Development >PHP Tutorial >PHP one-dimensional array loop traversal implementation method

PHP one-dimensional array loop traversal implementation method

墨辰丷
墨辰丷Original
2018-05-24 09:53:574772browse

A simple example of PHP looping 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 PHP An example of looping a one-dimensional array is to first convert the string into an array according to certain rules, and then traverse the output. It is actually a very simple method, because a two-dimensional array structure diagram I recently made was a headache, so I can't remember how to perform traversal output for a while. 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;; 
  } 
?>

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

The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

How to automatically load classes in PHP

PHP’s middleware ICE

PHP Two-dimensional array deduplication or statistics based on a certain field

The above is the detailed content of PHP one-dimensional array loop traversal implementation method. 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