For an explanation of the PHP array () syntax definition _php tutorial

Source: Internet
Author: User
PHP after a long period of development, many users are very familiar with PHP, here I publish a personal understanding, and we discuss the discussion, the PHP array is actually an ordered diagram. A graph is a type that maps values to keys.

This type is optimized in many ways, so you can use it as a real array, or list (vector), hash list (an implementation of the graph), dictionaries, collections, stacks, queues, and more possibilities. Because you can use another PHP array as a value, you can also easily emulate a tree. Explaining these structures is beyond the scope of this manual, but you will find at least one example for each structure. To get more information on these structures, we recommend that you refer to external writings on this broad topic. The following is a detailed description of the PHP array of relevant knowledge.

PHP array Syntax definition array ()

You can use the array () language structure to create a new array. It accepts a certain number of key=>value parameter pairs separated by commas.

 
 
  1. Array ([key=>]
  2. Value
  3. ,...
  4. )
  5. Key can be an integer or string
  6. Value can be any value
  7. php
  8. $ arr = Array ("foo" =>"Bar",n=>true);
  9. echo$arr["foo"];//bar
  10. Echo$arr[12];//1
  11. ?>

Key can be an integer or string. If the key name is a standard representation of an integer, it is interpreted as an integer (for example, "8" will be interpreted as 8, and "08" will be interpreted as "08"). The variable type of the array subscript in PHP is not affected by the array, there is only one type, it can contain both an integer and a string subscript, and the value can be any value.

 
  
  
  1. !--? php
  2. $ arr = array ("somearray" = ; Array ( 6 = ; 5, 13 = ; 9, "a" = ; 42));
  3. echo$arr["Somearray"][6];//5
  4. echo$arr[" Somearray "][13];//9
  5. echo$arr[" Somearray "[" a "];//42
  6. < span> ,

If no key name is specified for the given value, the current largest integer index value is taken, and the new key name is the value plus one. If you specify a key name that already has a value, the value is overwritten.

 
 
  1. php
  2. Thisarrayisthesameas ...
  3. Array (5=>43,32,56, "b" =>12);
  4. ... thisarray
  5. Array (5=>,6=>, 7 = > "B" = > 12);
  6. ?>

http://www.bkjia.com/PHPjc/446538.html www.bkjia.com true http://www.bkjia.com/PHPjc/446538.html techarticle PHP After a long period of development, many users are very familiar with PHP, here I publish a personal understanding, and we discuss the discussion, the PHP array is actually an ordered diagram. Figure is a kind of putting Val ...

  • 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.