PHP array functions (2)

Source: Internet
Author: User
Tags compact

conversion functions between arrays and variables
    1. List () language structure
      • Format: void list (mixed varname1[,mixed varname2[,mixed ...]) = array arr, assigning a set of variables in one step.
        • Note: the list () language structure is used only for arrays of numeric "keys" and requires the number "key" to increment continuously from 0;
    1. Extract () function
      • Format: int extract (array arr), use an array of arr to define a set of variables, where the variable name is the key name of the ARR element, and the variable value is the value of the array arr element "key".
    1. Compact () function
      • Format: Array compact (mixed varname1[,mixed varname2[,mixed ...]), returns an array of "keys" for each element named variable name varname1 (varname2 ...), each of the array elements " Value "is Variable varname1 (varname2 ...) The value.
Array Traversal language structure
    1. foreach (array as $value)
    2. foreach (array as $key = = $value)
For example:
<?PHP$interests[2] = "Music";$interests[6] = "movie";$interests[1] = "Computer";$interests[] = "Software";foreach($interests  as $value) {    Echo $value." <br> ";}foreach($interests  as $key=$value) {    Echo $key. "=".$value. "<br>" ;}?>
Results:

PHP array functions (2)

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.