PHP traverses the array code in three ways

Source: Internet
Author: User
: This article mainly introduces PHP code for traversing arrays. you can refer to these three methods for PHP tutorials. $ People = array ("Peter", "Joe", "Glenn", "Cleveland ");
$ People1 = array ("Peter", "Joe", "asd" => "Glenn", "Cleveland ");
// 7. list (variable 1, variable 2, variable 3); used together with each to traverse the array.
// The list function assigns values to a group of variables with elements in the array.
// This function is only used for the number index array, and it is assumed that the number index starts from 0.
List ($ a1, $ a2, $ a3) = $ people1; // assign the array people1 to list
Echo $ a1. $ a2. $ a3; // output the values in the list.
Echo"
";
// 6. each (array1); generates an array consisting of the key and key values of the elements pointed to by the current internal pointer of the array,
// Move the internal pointer forward.
Print_r (each ($ people ));
Print_r (each ($ people ));
Reset ($ people); // reset the pointer
// Give the key and value in people1 to list
While (list ($ key, $ val) = each ($ people1 ))
{
Echo "$ key => $ val
";
}
For ($ I = 0; $ I Echo $ people [$ I]."
";
}
Foreach ($ people as $ v ){
Echo $ v ."
";
}

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above introduces the PHP code for traversing arrays, three methods, including content, hope to be helpful to friends who are interested in PHP tutorials.

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.