Explore the essential PHP array functions that power your web development projects.
Learn how to filter, transform, compare, and manipulate arrays efficiently with this comprehensive guide.
You are going to learn:
Array Filtering Functions Array Filtering Functions
- array_filter: Filter the array based on a provided callback function.
Array Key Transformation Functions Array Key Transformation Functions
- array_change_key_case: Change the case of all keys in the array.
- array_chunk: Split an array into chunks of a specified size.
- array_column: Extract a single column of values from a multi-dimensional array.
- array_combine: Create an array by using one array for keys and another for values.
- array_count_values: Count the occurrences of values in an array.
Array Comparison Functions Array Comparison Functions
- array_diff_assoc: Compute the difference of arrays with additional key comparison.
- array_diff_key: Compute the difference of arrays using keys for comparison.
- array_diff_uassoc: Compute the difference of arrays with additional key comparison, using a user-defined key comparison function.
- array_diff_ukey: Compute the difference of arrays using a user-defined key comparison function.
- array_diff: Compute the difference of arrays.
- array_intersect_assoc: Compute the intersection of arrays with additional key comparison.
- array_intersect_key: Compute the intersection of arrays using keys for comparison.
- array_intersect_uassoc: Compute the intersection of arrays with additional key comparison, using a user-defined key comparison function.
- array_intersect_ukey: Compute the intersection of arrays using a user-defined key comparison function.
- array_intersect: Compute the intersection of arrays.
Array Key Functions Array Key Functions
- array_is_list: Check if an array is a list (sequential).
- array_key_exists: Check if a specific key exists in the array.
- array_key_first: Get the first key of an array.
- array_key_last: Get the last key of an array.
- array_keys: Return all the keys of an array.
Array Transformation Functions Array Transformation Functions
array_map
: Apply a callback function to all elements of an array.array_merge_recursive
: Merge multiple arrays recursively.array_merge
: Merge multiple arrays.array_multisort
: Sort multiple arrays, or multi-dimensional arrays, by one or more columns.array_pad
: Pad an array to a specified length with a specific value.array_reverse
: Reverse the order of elements in an array.array_replace_recursive
: Replace values in the first array with corresponding values from following arrays, recursively.array_replace
: Replace values in the first array with corresponding values from following arrays.
Array Manipulation Functions Array Manipulation Functions
array_search
: Search for a value in an array and return the corresponding key.array_shift
: Shift an element off the beginning of an array.array_slice
: Extract a portion of an array.array_splice
: Remove a portion of the array and replace it with something else.array_sum
: Calculate the sum of values in an array.array_udiff_assoc
: Compute the difference of arrays with additional key comparison, using a user-defined key comparison function.array_udiff_uassoc
: Compute the difference of arrays with additional key comparison, using user-defined key comparison functions.array_udiff
: Compute the difference of arrays using a user-defined comparison function.array_uintersect_assoc
: Compute the intersection of arrays with additional key comparison, using a user-defined key comparison function.array_uintersect_uassoc
: Compute the intersection of arrays with additional key comparison, using user-defined key comparison functions.array_uintersect
: Compute the intersection of arrays using a user-defined comparison function.array_unique
: Remove duplicate values from an array.array_unshift
: Prepend one or more elements to the beginning of an array.array_values
: Return all the values from an array.array_walk_recursive
: Apply a user-defined function recursively to every member of an array.array_walk
: Apply a user-defined function to every member of an array.
Array Basic Functions Array Basic Functions
array
: Create an array.arsort
: Sort an array in reverse order, maintaining key to index correlations.asort
: Sort an array in ascending order, maintaining key to index correlations.compact
: Create an array containing variables and their values.count
: Count the number of elements in an array.current
: Return the current element in an array.end
: Move the internal pointer to the last element of an array.extract
: Import variables into the current symbol table from an array.in_array
: Check if a value exists in an array.key_exists
: Alias forarray_key_exists
.key
: Fetch a key from an array.krsort
: Sort an array by key in reverse order.ksort
: Sort an array by key in ascending order.list
: Assign variables as if they were an array.natcasesort
: Sort an array using a case-insensitive natural order algorithm.natsort
: Sort an array using a natural order algorithm.next
: Advance the internal pointer of an array.pos
: Alias forcurrent
.prev
: Rewind the internal pointer of an array.range
: Create an array containing a range of elements.reset
: Reset the internal pointer of an array.rsort
: Sort an array in reverse order.shuffle
: Shuffle an array.sizeof
: Alias forcount
.sort
: Sort an array in ascending order.uasort
: Sort an array with a user-defined comparison function and maintain key to index correlations.uksort
: Sort an array by keys using a user-defined comparison function.usort
: Sort an array with a user-defined comparison function.