Loop-through implementation code for PHP one-dimensional arrays

Source: Internet
Author: User
This article introduces the content of the PHP one-dimensional array of loop traversal implementation code, has a certain reference value, now share to everyone, the need for friends can refer to

A simple example of a PHP loop 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

A simple example of a PHP loop one-dimensional array, first the string according to certain rules to convert into an array, and then traverse the output, is actually a very simple method, because a recently done a two-dimensional array structure diagram is a headache, so womb can't remember how to traverse the output. The simple example code is as follows:

foreach Traversal array


<?php  /* * Array Traversal  *   /$language = Array ("French", ' German ', ' Russian ', ' Chinese ', ' Hindi ', ' Quechu ');   foreach ($language as $key = + $value) {     echo $key. ' = '. $value. ' <br/> ';   } ?>


Traversal of associative arrays


<?php    /* * Associative array traversal    *    /$userList = Array (' UserName ' = ' Lilia ', ' Gender ' = ' female ', ' age ' = > ' Up ', ' School ' = ' Peking University ');    foreach ($userList as $key = + $value)    {     echo $key. ' = '. $value. ' <br/> ';    } ?>


This is a very simple example, every time you use the time to GG, it is troublesome, simply record down, use when the direct excerpt is good.

Related recommendations:

Example of converting PHP one-dimensional arrays to two-dimensional arrays

A comparative analysis of PHP one-dimensional array traversal method

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.