Php array (2) add elements to the array header
Array_unshift ($ states, 'AAA'); add aaa to the header of the array $ states, that is, the first
Add elements at the end of the array
Array_push ($ states, 'AAA'); add aaa to the end of the array $ states, that is, the last
Delete element from array header
Array_shift ($ states); deletes the first element of the array $ states
Deletes an element from the end of an array.
Array_pop ($ states); delete the last element of the array $ states
Returns true and false when searching for a specific value of an array.
In_array ($ states, 'AAA'); searches for the $ states array to check whether the value aaa exists. if the value aaa exists, true is returned.
Returns true and false when searching for the key of the associated array.
Array_key_exists ('AAA', $ states) returns true if the key in the array $ states contains an aaa key.
Search for the value of the associated array
Array_search ('AAA', $ states) returns true if the value of $ states in the array contains the value aaa. this is a bit like in_array, but this is dedicated to searching associated arrays, the latter is to search all arrays, including normal arrays
Obtain the array key
$ Keys = array_keys ($ states); the keys of all the arrays are returned and arranged as normal arrays, such as Array ([0] => aaa, [1] => bbb)
Get array value
$ Values = array_values ($ states); similar to the above.
Get the current array key
$ Test = array ('AAA' => 'we', 'BBB '=> 'you'); while ($ key = key ($ test )) {// The key () is the key used to obtain the current array. The key is queried sequentially from 0. Therefore, the first key is aaa, and the second key is bbb echo $ key; next ($ test); // because the key does not move the array pointer and points to a key, it does not change. Therefore, you need to use the next method to move to the next pointer}
Get the current array value
Similar to the above, but the key is changed to current
Obtains the keys and values of the current array.
Similar to the above, use each
Move an array pointer
There are "next", "prev", "reset", and "end", which are respectively the next, first, first, and last.
Refer to the previous next example.
Determine the array size
count($garden);
Count the frequency of array keys
Array_count_values ($ states); return value: Array ([aaa] => 2, [bbb] => 1)
Determine unique array elements
Deletes all repeated values in the array and returns an array consisting of unique values.
array_unique($states);