Analysis of PHP composite data type array usage. For example, data type is a hard-to-understand knowledge point. in this article, we will explain how to use PHP composite data type array, data type is a hard-to-understand knowledge point. in this article, we will explain how to use PHP composite data type array, and hope to help you.
(1) array: arrays in PHP use an optimized ordered graph type as an array. Always put quotation marks on the array index represented by a string (except a constant or variable.
PHP composite data type array definition array ():
Array ([key =>] // key can be integer or string
Value // value can be any value
,...
)
- <? Php
- $ Arr = array ("foo" => "bar", 12 => true); // if the key is a floating point, it is rounded to integer.
-
- Echo $ arr ["foo"]; // bar
- Echo $ arr [12]; // 1
- ?>
The default key name of the PHP composite data type array takes the current maximum integer index value, and the new key name index adds one to the current maximum index. If the specified key name already has a value, the value will be overwritten. Since PHP 4.3.0, the above index generation method has changed. If you add a new value to an array whose current maximum key name is a negative value, the newly generated index will be zero (0 ). Previously, the newly generated index is the current maximum index plus one, which is the same as the positive index.
Add/modify array elements:
- < ?php
- $arr = array(5 => 1, 12 => 2);
- $arr[] = 56; // This is the same as $arr[13] = 56;
- // at this point of the script
- $arr["x"] = 42; // This adds a new element to
- // the array with key "x"
- unset($arr[5]); // This removes the element from the array
- unset($arr); // This deletes the whole array
- ?>
The introduction of PHP composite data type array is here. I hope you can master this knowledge point.
...