PHP Learning Notes--multiple traversal methods commonly used in arrays

Source: Internet
Author: User

traversal of an array * * 1. Loop through the array using the FOR statement * A. Other languages (only this way) * B. This way in PHP is not our preferred method * C. The array must be an indexed array, and the subscript must also be contiguous * (Index array subscript Also Can be non-sequential, arrays also have associative arrays) * * * 2. Iterate through an array with a foreach statement * foreach (array variable as variable value) {*//loop body *} * A. The number of cycles is determined by the number of elements in the array * b. Each loop assigns the elements in the array to the following variable * * f Oreach (array variable as subscript variable = = value variable) {* *} * * 3. The while () list () all () combination loops through the array * * each () function, * A. An array is required as a parameter * B. The returned array is also an array of * C. Returned arrays are 0, 1, ke              Y, value four subscript (fixed) * 0 and key subscript are the keys of the current parameter array element * 1 and value subscript is the value of the current logarithmic array element * d. The default is that the current element is the first element * E. The current element is moved backwards after each execution * f. If the function is executed again to the last element, False * *//array ([1] = 1 [value] = 1 [0] + = ID [key] = + ID) * * list () function * A. List () =array (); You need to assign an array to the function * B. The number of elements in the array is the same as the number of parameters in the list () function * C. Each element value in the array is assigned a value of each parameter in the list () function, and list () converts each parameter to the variable * d. list () can only receive indexed array * E The index's subscript order *//* $user =array ("id" =>1, "name" = "Zhangsan", "Age" =>10, "Sex" and "Nan"), while ($arr =each ($user)) {//echo $Arr[0]. " ==> ". $arr [1]." <br> "; Echo $arr [" Key "]." ----> ". $arr [" Value "]." <br> ";} Use the inner pointer of the array to control the function next (array);p rev (array), reset (array) end (array), current (array), key (array); */

Explode () function string split into array function

PHP Learning Notes--multiple traversal methods commonly used in arrays

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.