PHP =

Source: Internet
Author: User
PHP =
Example 1 in this example, the ID key is automatically assigned: $names = Array ("Peter", "Quagmire", "Joe"), example 2 in this example, we manually assign the ID key: $names [0] = "Peter"; $names [1] = "Qu Agmire "; $names [2] =" Joe "; you can use these ID keys in your script:
 Output from the above code: Quagmire and Joe are Peter's neighbors associative array, which each ID key associates with a value. Using numeric arrays is not the best practice when storing data about a specific named value. With associative arrays, we can use values as keys and assign values to them. Example 1 in this example, we use an array to assign age to different people: $ages = Array ("Peter" =>32, "quagmire" =>30, "Joe" =>34); Example 2 This example is the same as Example 1, But it shows another way to create an array: $ages [' Peter '] = "All", $ages [' quagmire '] = "34", $ages [' Joe '] = "+"; you can use the ID key in the script:
 Output from the above script: Peter is years old. Multidimensional arrays in multidimensional arrays, each element in the primary array is also an array. Each element in a sub-array can also be an array, and so on. Example 1 in this example, we create a multidimensional array with an auto-assigned ID key: $families = Array ("Griffin" =>array ("Peter", "Lois", "Megan"), "quagmire" =& Gt;array ("Glenn"), "Brown" =>array ("Cleveland", "Loretta", "Junior")); If you output this array, it should look like this: Array ([Griffin] = > Array ([0] = Peter [1] = Lois [2] = Megan) [quagmire] + array ([0] = = Glenn) [Brown] =&G T Array ([0] = Cleveland [1] = Loretta [2] = Junior))
  • 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.