Php array (1) The php array index starts from 0, not 1.
$ States [0] // A normal array can use the sequence number as the key $ states ['A'] // The associated array uses a key-value pair to call $ states ['A'] [' aaa'] // This method can be used to call multiple arrays.
-
In php, no matter whether an associated array or a numeric key is used, it depends on an array pointer. the array pointer is like a bookmark, indicating the array bit being checked.
-
Instead of directly operating the array pointer, you use the built-in language features or functions to traverse the array.
-
In php, all array management methods are actually operating the array pointer, but the pointer operation methods are built in php or encapsulated by functions.
Directly create an array
$states[0] = 1;$states[] = 1;$states['aa'] = 1;
Use array () to create an array
$languages = array('spain'=>'spanish','ireland'=>'english');
Extract 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); // use explode to separate | as a separator and divide it into three parts, then, use the "list" command to separate the three variables into the three variables} echo $ name; echo $ sex; echo $ age;
Use range to generate an array
$ Test = range (); // generates an array of 6 elements ranging from 1 to 6. $ test = range (, 2); // The third parameter is the step size, the step size is probably the meaning of the interval. here 1 3 5... is generated .... Value with an interval of 2
Test array
Use is_array for testing. true and false are returned.
Print array
Print with print_r
Print_r ($ states); // Print the array through traversal