Array_unshift () // Add an element to the array header, that is, insert a new element into the array, and the corresponding index is automatically changed.
Array_push () // Add an element at the end of the array
Array_shift () // delete an element in the array Header
Array_pop () // delete an element at the end of the array
The usage of these functions is almost the same. You can get the specific usage in the PHP help manual.
PHP code example for searching Arrays:
The in_array () function searches for a specific value in the array. If it is found, TRUE is returned. Otherwise, FALSE is returned. The following example is from the PHP help manual.
- < ?php
- $os = array("Mac", "NT", "Irix", "Linux");
- if (in_array("Irix", $os)) {
- echo "Got Irix";
- }
- if (in_array("mac", $os)) {
- echo "Got mac";
- }
- ?>
In particular, in_array () is distinguished by size during search, so the above example only returns "Got Irix ". You can also use arrays as substrings to search in arrays. For more examples, see the help manual.
Search join array for PHP search Array
If the search array is an associated array, array_key_exists () is used. The returned value is the same as that of in_array. We also reference the PHP help manual example to illustrate:
- < ?php
- $search_array = array('first' => 1, 'second' => 4);
- if (array_key_exists('first', $search_array)) {
- echo "The 'first' element is in the array";
- }
- ?>
I believe that this piece of code should not be explained. The result is as follows: the 'first 'element is in The array. This indicates that "first" exists in the array "search_array.