The array index of PHP is starting at 0 instead of 1.
$states [0]//ordinary array can be used as the key $states[' AA '//correlation array with a key value pair to call $states[' AA ' [' AAA ']//multiple arrays can be called in this way
-
Whether an associative array or a numeric key is used in PHP is dependent on an array pointer's property, the array pointer is like a bookmark that tells you the array bit being checked.
-
Instead of manipulating array pointers directly, you use built-in language attributes or functions to iterate through the array
-
This means that in PHP, all the array management methods are actually manipulating the array pointers, only the method of manipulating pointers is PHP built-in or is encapsulated by the function.
Create an array
Directly create
$states [0] = 1; $states [] = 1; $states [' AA '] = 1;
Creating arrays with Array ()
$languages = Array (' Spain ' = ' Spanish ', ' ireland ' = ' 中文版 ');
Extracting an array with list
File Users.txt Content a|b|c$users = fopen (' Users.txt ', ' R '), while ($line = Fgets ($users, 4096)) { list ($name, $sex, $age) = Explode ("|", $line); by explode | As the delimiter, and then divided into 3 parts, and then use list to add these 3 parts into 3 variables}echo $name; echo $sex; Echo $age;
Using range to generate an array
$test = range (1,6); Generates an array of 6 elements with a value of 1 to 6 $test = range (1,10,2); The third parameter is the step size, which is probably the meaning of the interval, which generates 1 3 5 .... Value at Interval of 2
Test array
Test with Is_array, return true and False
Print array
Use Print_r to print
Print_r ($states); Traversing a printed array