PHP array operation function summary. The most common data structure in PHP is an array. arrays can help us solve a large part of programming problems. In fact, many array operations do not need to be written by ourselves. the system already comes with an array which is the most commonly used data structure in PHP. arrays can help us solve a large part of programming problems. In fact, many array operations do not need to be written by ourselves. the system already comes with related functions. Next we will introduce some functions related to PHP array operations, which you may not have heard.
- Search for a specific value in the array. If yes, return TRUE. Otherwise, return FALSE.
boolean in_array(mixed needle,array haystack[,boolean strict])
- Find a specified key in the array. If yes, return TRUE. Otherwise, return FALSE.
boolean array_eky_exists(mixed key,array array)
- Search for a specific value in the array. If yes, return TRUE. Otherwise, return FALSE.
boolean array_search(mixed needle,array haystack[,boolean strict])
- Obtains a new array composed of all the keys in the array.
array array_keys(array array[,mixed search_value])
- Obtains a new array composed of all values of the array.
array array_values(array array)
- Determine the array size
integer count(array array[,int mode])integer sizeof(array array[,int mode])
- Count the occurrence frequency of array elements
array array_count_values(array array)
- Deletes repeated values in an array and returns an array consisting of unique values.
array array_unique(array array)
- Returns the element order of the array. if the value of preserve_key is TRUE, the order of the key values of the array remains unchanged.
array array_reverse(array array[,boolean preserve_key])
- Replace the array key and value
array array_flip(array array)
- Sort arrays sequentially. the sort_flags parameter is optional. default behavior.
SORT_NUMBERIC, sorted by numerical value, SORT_REGULAR is useful for sorting integers or floating-point numbers, SORT_STRING is sorted by ASCII value, sort the keys and values of the asort function in the correct order recognized by the audience unchanged void sort (array [, int sort_flags]) void asort (array [, int sort_flags])
- Array sorting in reverse order. the sort_flags parameter is optional. default behavior.
SORT_NUMBERIC, sorted by numerical value, SORT_REGULAR is useful for sorting integers or floating-point numbers, SORT_STRING is sorted by ASCII value, sort arsort function key values in the correct order recognized by the nearest person. The order of void rsort (array [, int sort_flags]) void arsort (array [, int sort_flags]) remains unchanged.
- Natural sorting of arrays
void natsort(array array)
- Case-insensitive natural sorting
void natcasesort(array array)
- Sort the key-value pairs in an array
boolean ksort(array array[,int sort_flags])
- Sort the key-value pairs in reverse order.
boolean krsort(array array[,int sort_flags])
- Sort by user-defined order
void usort(array array,callback function_name)
- Merges the arrays to return a Union array. Array_merge overwrites the front, and array_merge_recursive is merged.
Array array_merge (array array1 [array array2…]) // More than one array array_merge_recursive (array array1, array array2 [, array…]) // More than two
- Key and value form a new array
array array_combine(array key,array value)
- Returns a part of the array, starting from the offset and ending at the offse + length position.
array array_slice(array array, int offset [,int length])
- Delete all elements starting from offset to ending with offset + length, and return the deleted elements as arrays.
array array_splice(array, int offset [,int length[,array peplacement]])
- Returns the intersection of arrays. The key value is the key value in the first array.
array array_intersect(array array1,array array2[,arrayN……])
- The intersection of the array contains the same key value. The key value is the key value of the first array.
array array_intersect_assoc(array array1,array array2[,arrayN……])
- Evaluate the difference set of the array. the first array does not have values in other arrays.
array array_diff(array array1,array array2[,arrayN……])
- Evaluate the difference set of the array. the first array does not have the same key value in other arrays.
array array_diffassoc(array array1,array array2[,arrayN……])
- Returns one or more key values in the array.
mixed array_rand(array array[,int num_entries])
- Shuffling function
void shuffle(array input_array)
- Summation of values in the array
mixed array_sum(array array);
- Splits an array into a multi-dimensional array that contains size elements.
array array_chunk(array array, int size [,boolean preserve_keys])
Bytes. In fact, there are a lot of array operations that we do not need to write, the system already comes with the phase...