Home > Article > Backend Development > What is an indexed array in PHP
In PHP, an index array refers to an array with numbers as keys (subscripts). The subscript (key name) of the index array consists of numbers, starting from 0 by default. Each number corresponds 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. It then automatically increments from this value.
The operating environment of this tutorial: windows7 system, PHP version 8.1, DELL G3 computer
Array is one of the most important data types in PHP First, it is widely used in PHP. Because PHP is a programming language with weak data types, array variables in PHP can store any number of data of any type, and can implement the functions of data structures such as heaps, stacks, and queues in other strong data types.
Array An array is an ordered set of variables, where each value is called an element. Each element is distinguished by a special identifier called a key (also called a subscript).
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.
PHP arrays are divided into two types:
Those with numbers as key names are called indexed arrays (Indexed Array);
Arrays with strings or a mixture of strings and numbers as keys are called associative arrays (Associative Array).
Index array
The subscript (key name) of the index array consists of numbers, starting from 0 by default, and each number corresponds to an array The position of the element in the array does not need to be specified. PHP will automatically assign an integer value to the key name of the index array, and then automatically increase from this value.
<?php header('content-type:text/html;charset=utf-8'); $arr = array('华为','三星','vivo','oppo'); var_dump($arr); echo '数组 $arr 中的,键名为2的键值为:'.$arr[2]; ?>
Note: If a key name in an array is not a number, then the array is not an index array, but an associative array.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is an indexed array in PHP. For more information, please follow other related articles on the PHP Chinese website!