Home > Article > Backend Development > Does php array only support numeric subscripts?
No, the subscript (index value) of the PHP array can be a string or a number. The array whose subscript is a string is an associative array, which is an array with a special indexing method; the array whose subscript is a number is an index array, and its subscript value must be an integer, starting from 0 and so on.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In PHP, under the array The index (index value) can be a string or a number.
The array whose subscript is a string is an associative array
The array whose subscript is a number is an index array
Index array
Index array stores an organized sequence of single or multiple values, each of which can be identified by using an unsigned integer value for a visit. The keys of the index array are integers and start from 0 and so on.
Associative array
"Associative array" is an array with a special indexing method. Index it using a string or other type of value (except NULL).
In fact, the difference between associative arrays and index arrays is only in the key values. The key values of associative arrays are strings, and they are artificial regulations.
<?php header("Content-type:text/html;charset=utf-8"); //创建一个关联数组,关联数组的键“orange”,值是“橘子” $age=array("Peter"=>"35","Ben"=>"43","Joe"=>"42"); var_dump($age); ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of Does php array only support numeric subscripts?. For more information, please follow other related articles on the PHP Chinese website!