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.
- Array ([key=>]
- Value
- ,...
- )
- Key can be an integer or string
- Value can be any value
- php
- $ arr = Array ("foo" =>"Bar",n=>true);
- echo$arr["foo"];//bar
- Echo$arr[12];//1
- ?>
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.
- !--? php
- $ arr = array ("somearray" = ; Array ( 6 = ; 5, 13 = ; 9, "a" = ; 42));
- echo$arr["Somearray"][6];//5
- echo$arr[" Somearray "][13];//9
- echo$arr[" Somearray "[" a "];//42
- < 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.
- php
- Thisarrayisthesameas ...
- Array (5=>43,32,56, "b" =>12);
- ... thisarray
- Array (5=>,6=>, 7 = > "B" = > 12);
- ?>
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 ...