Array

43 entries

array_change_key_case Function Converts all array keys to lowercase or uppercase (CASE_LOWER/CASE_UPPER); the dedicated tool for normalizing HTTP headers and config keys. array_chunk Function Splits an array into chunks of a fixed length. array_column Function Extracts the values of a given column from a two-dimensional array. array_combine Function Creates a map array using one array as keys and the other as values; both arrays must have equal length. array_count_values Function Counts occurrences of each value in an array, returning a map of value => count (a value histogram). Elements must be int/string; the result keeps first-seen order. array_diff Function Computes the array difference: values in the first array that are absent from the others, preserving order and keys. array_diff / array_intersect family Function Two set-operation families: difference (diff) and intersection (intersect), each with key / assoc / uassoc / ukey comparison variants. Values compare loosely as strings, keys and order are kept — the complete PHP array set-operation toolbox. array_fill Function Fills an array with a given value a specified number of times, starting at a chosen index. array_fill_keys Function Fill from a key array: the values of $keys become the keys and one shared $value fills the whole table (the mirror direction of array_fill, which fills by index range); numeric-string keys coerce to int per PHP convention. array_filter Function Filters array elements with a callback function. array_flip Function Swaps keys with values in an array (on duplicate values the later key wins). array_intersect Function Computes the array intersection: values present in every array, ordered by the first array. array_is_list Function Whether the array is a "true list" (sequential 0..n-1 integer keys); the health-check tool for PHP's two array faces - json_encode emits an array or an object depending on which face shows. array_key_exists Function Checks whether a key exists regardless of its value — the correct answer to the classic trap where isset() returns false for keys whose value is null. array_key_first Function Gets the first key of an array without moving the internal pointer. array_key_last Function Gets the last key of an array without moving the internal pointer. array_keys Function Returns all keys of an array. array_map Function Applies a callback to every element of an array and returns a new array. array_merge Function Merges one or more arrays. array_merge_recursive / array_replace_recursive Function Recursive merging and replacing of nested arrays: merge_recursive aggregates colliding scalar values into an array (port becomes [3306,5432]), while replace_recursive lets the later array overwrite deep down. Neither mutates the originals — the behavioral contrast is the key point when merging configs. array_all / array_any / array_find … Function PHP 8.4's modern callback quartet (array_all/array_any/array_find/array_find_key - callback takes value and key, short-circuits) plus 8.5's array_first/array_last, each with its native counterpart in other languages. array_pad Function Pads an array to a given length: positive pads right, negative pads left, and the array is returned untouched when long enough; pairs with array_slice as the truncate+pad pagination combo. array_pop Function Pops and returns the last element of the array, shortening the array by one element. array_push Function Pushes one or more elements onto the end of the array and returns the new count (equivalent to $array[] = $value). array_rand Function Picks one or more random keys from an array (a single pick returns the key itself; multiple picks return keys in original order). Since 7.1 it shares the global Mersenne Twister with mt_rand, so mt_srand makes it reproducible; not cryptographically secure. array_reduce Function Reduces an array to a single value using a callback. array_replace Function Later arrays overwrite earlier ones key by key, returning a new array: assignment-replacement, not recursive merging — nested arrays are swapped wholesale (timeout disappears), the shallow counterpart of the existing array_replace_recursive's deep merge. array_reverse Function Returns a new array with the elements in reversed order. array_search Function Searches an array for a value and returns its key, or false when not found. array_shift Function Removes and returns the first element of the array, shifting the remaining elements one position forward. array_slice Function Extracts a slice of an array. array_splice Function Removes and replaces a segment in place: modifies the original array and returns the removed part; complements read-only array_slice. Negative offsets count from the tail; replacement keys are not preserved. array_sum / array_product Function Numeric aggregation: array_sum adds and array_product multiplies; empty arrays return the additive/multiplicative identities 0 and 1; float accumulation follows array order. array_unique Function Removes duplicate values from an array. array_unshift Function Prepends one or more elements to the beginning of the array and returns the new element count. array_values Function Returns all values of an array (rebuilding numeric indexes). array_walk Function Applies a callback to every element in place (the callback may modify elements by reference). array_walk_recursive Function Recursively walks nested arrays and calls back only on scalar leaves — contrast with array_walk (single level): the depth difference decides the use case; no direct counterpart in other languages, hand-write recursion or tree enumeration. compact / extract Function A two-way bridge between variables and arrays: compact packs variables into an array by name; extract imports array keys into the current symbol table as variables. extract overwrites same-named variables by default — never use it on untrusted data. count Function Counts the number of elements in an array. in_array Function Checks whether a value exists in an array. range Function Range arrays: eagerly builds an arithmetic array from start/end/step — integers auto-detect direction (no negative step needed), characters have builtin sequences (range('a','e')), float steps are allowed; the end is included in the result (opposite of Python's exclusive stop). sort Function Sorts array elements in place in ascending order.