: This article mainly introduces common array functions in php. For more information about PHP tutorials, see. 1. locate the array:
- Bool in_array (mixed needle, array haystack [, bool strict]) to find the specified element;
- Array array_keys (arraqy input [, mixed search_value]) an array composed of return key values;
- Bool array_key_exists (mixed key, array search) determines whether the key value is the specified key value;
- Array array_values (array input) returns the element values in the array;
- 2. traverse the array:
- Mixed key (array input) returns the key value of the current pointer element;
- Mixed reset (array input_array) resets the pointer to the starting position of the array;
- Array each (array input_array) returns the array value of the current pointer position;
- Mixed current (array input_array) returns the value of the array element at the current pointer position;
- Mixed end (array input_array) returns the current pointer pointing to the last element;
- Mixed next (array input_array) returns the array element at the next position of the current pointer;
- Mixed prev (array input_array) returns the array value located in the previous position of the current pointer;
- 3. add and delete array elements:
- Int array_push (array & array, mixe var [, mixed...]) to add the specified value to the end of the array;
- Mixed array_pop (array & array) returns the last element of the array and resets the array pointer;
- Mixed array_shift (array target_array) returns the first element value of the array;
- Int array_unshift (array & array, mixed var [, mixed...]) to add the specified element to the starting position
- Array array_pad (array input, int pad_size, mixed pad_value) adds the array to the specified length.
- 4. sort arrays:
- Bool sort/rsort (array & array [, int sort_flags]); ascending and descending;
- 5. Merge and split arrays:
- Array array_combine (array keys, array values) array merging;
- Array array_merge (array array1 [, array array2 [array...]) combines multiple numbers and returns a new array;
- Array array_slice (array, int offset [, int length]) extracts the specified length from the specified position of the array and saves it to a new array;
- Array explode (string separator, string) is separated and the result is saved;
- Array implode (string glue, array pieces) specifies a new character for the element to be connected through a string;
- 5. create an array of the specified range:
- Array range (mixe low, mixed high [, number step]) to create an array of the specified range;
- Array shuffle ($ array) random sorting of elements in the specified array;
- Number array_sum (array input_array) sums all elements;
The above describes the common array functions in php, including the content, and hope to help those who are interested in the PHP Tutorial.