php index array has key values. In PHP, whether it is an index array or an associative array, each entity in the array contains two items, namely key and value; there is no difference between the two arrays in the key value, but in the key name There is a difference: the index array uses numbers as keys, while the associative array uses strings or a mixture of strings and numbers as keys.
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, DELL G3 computer
The php index array has key values.
PHP arrays can be divided into two types: index arrays and associative arrays.
But whether it is an index array or an associative array, each entity in the array contains two items, namely key and value. The corresponding array elements can be obtained by key value. These keys can be numeric keys or association keys. If a variable is a container that stores a single value, then an array is a container that stores multiple values.
Both index arrays and associative arrays have key values. There is no difference in the key values. The difference lies in the key name:
The index array uses numbers as the key name
Associative arrays use strings or a mixture of strings and numbers as keys.
Explanation:
The subscript (key name) of the index array consists of numbers, starting from 0 by default, each number Corresponding to the position of an array element in the array, there is no need to specify it. PHP will automatically assign an integer value to the key name of the index array, and then automatically increase from this value.
The subscript (key name) of an associative array is composed of a mixture of numerical values and strings. If a key name in an array is not a number, then the array is an associative array.
"1","a"=>"red",2=>"2","b"=>"green","c"=>"blue"); var_dump($arr2); ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of Does the php index array have key values?. For more information, please follow other related articles on the PHP Chinese website!