PHP array () syntax definition _ PHP Tutorial

Source: Internet
Author: User
For details about the syntax definition of the PHP array. After a long history of PHP development, many users are familiar with PHP. here I will share my personal understanding and discuss it with you. the PHP array is actually an ordered graph. The figure shows how val PHP has been developing for a long time. many users know PHP very well. here I will share my personal understanding and discuss it with you, the PHP array is actually an ordered graph. A graph is a type that maps values to keys.

This type has been optimized in many ways, so you can use it as a real array, or a list (vector), a hash (an implementation of a graph), a dictionary, set, stack, queue, and more possibilities. Because another PHP array can be used as the value, and the tree can be easily simulated. Interpreting these structures is beyond the scope of this manual, but you will find at least one example for each structure. For more information about these structures, we recommend that you refer to external works on this broad topic. Next we will introduce in detail the knowledge about PHP arrays.

PHP array syntax definition array ()

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

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

The key can be an integer or string. If the key name is an integer standard expression, it is interpreted as an integer (for example, "8" will be interpreted as 8, and "08" will be interpreted as "08 "). The variable type under the array in PHP does not affect the array. the array type has only one type. it can contain both the subscript of the integer type and the string type, 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. ?>

If no key name is specified for the given value, the current maximum integer index value is used, and the new key name is the value plus one. If the specified key name already has a value, the value will be overwritten.

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

Bytes. The image is a type of 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.