PHP Syntax Basics 6

Source: Internet
Author: User

foreach traversal

Basic syntax:

foreach ( array name as key variable = = value variable )

{

Loop Body

}

foreach ( array name as value variable )

{

Loop Body

}


Array pointer-related functions

Key ( array name ): Gets the key of the current element of the array

Current ( array name ): Gets the value of the present element of the array

Next ( array name ): Moves the array pointer down one

Reset ( array name ): resets the pointer to the array (the pointer to the array is re-directed to the first element)

End ( array name ): is reset to the last element!

Prev ( array name ): moves the array pointer up

Each ( array name ):: the function of key,current,next function

$each [0],$each [' key '] represents the key of the current element of the original array,$each [1],$each [' value '] represents the value of the current element of the original array


List: is a system function, it can use an indexed array, one-time to assign values to multiple variables!

List ($v 1, $v 2, $v 3) = $arr: $v 1 corresponds to $arr 1[0], $v 2 corresponds to $arr 1[1], $v 3 corresponds to $arr 1[2]


Common array Functions:

COUNT ( array name ): calculates and returns the number of elements in an array or the number of attributes in an object

Range: calculates and returns the number of elements in an array or the number of attributes in an object

Range (A,B,C): A: start character or number ; B: end character or number ; C Pace ( can save, default is 1): Jump a few characters or numbers at a time

Array_merge (): merges the cells of one or more arrays, and the values in an array are appended to the previous array. Returns an array as the result.

Array_rand: The function is to randomly extract the keys of several elements within the array! and returns an indexed array!


PHP Syntax Basics 6

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.