PHP Array Functions
PHP ships with a large set of built-in functions for working with arrays.
These are the ones you are most likely to reach for:
array()- Builds a new arrayarray_change_key_case()- Converts every key to lowercase or uppercasearray_chunk()- Breaks an array into smaller arrays, or chunksarray_column()- Picks out the values of one column from the input arrayarray_combine()- Builds an array from two others, one supplying the keys and the other the valuesarray_count_values()- Counts how many times each value appearsarray_diff()- Compares arrays and gives back the differences, looking at values onlyarray_diff_assoc()- Compares arrays and gives back the differences, looking at both keys and valuesarray_diff_key()- Compares arrays and gives back the differences, looking at keys onlyarray_fill()- Populates an array with a value you choosearray_fill_keys()- Populates an array with a value, using the keys you listarray_filter()- Keeps only the values that a callback function acceptsarray_flip()- Swaps each key with its valuearray_intersect()- Compares arrays and gives back what they have in common, looking at values onlyarray_intersect_assoc()- Compares arrays and gives back what they have in common, looking at both keys and valuesarray_intersect_key()- Compares arrays and gives back what they have in common, looking at keys onlyarray_key_exists()- Tells you whether a given key is in the arrayarray_keys()- Gives back all of an array's keysarray_map()- Passes each value to a function you write and collects the new values it returnsarray_merge()- Combines one or more arrays into a single arrayarray_merge_recursive()- Combines one or more arrays into a single array, working recursivelyarray_multisort()- Sorts several arrays at once, or a multidimensional arrayarray_pad()- Extends an array to a given length, filling the new items with a value you specifyarray_pop()- Takes the last element off the arrayarray_product()- Multiplies all the values togetherarray_push()- Appends one or more elements at the endarray_rand()- Picks one or more keys at randomarray_reduce()- Reduces an array to a single value with a function you writearray_replace()- Overwrites the first array's values with those from the arrays after itarray_replace_recursive()- Overwrites the first array's values with those from the arrays after it, working recursivelyarray_reverse()- Gives back the array with its order reversedarray_search()- Looks for a value and gives back its keyarray_shift()- Takes the first element off the array and gives it back to youarray_slice()- Gives back a selected part of an arrayarray_splice()- Cuts out chosen elements and can put others in their placearray_sum()- Adds up all the valuesarray_unique()- Drops duplicate valuesarray_unshift()- Places one or more elements at the startarray_values()- Gives back all of an array's valuesarray_walk()- Runs a function you write on every elementarray_walk_recursive()- Runs a function you write on every element, working recursivelyarsort()- Sorts an associative array by value, high to lowasort()- Sorts an associative array by value, low to highcompact()- Builds an array from variables and their valuescount()- Tells you how many elements an array hascurrent()- Gives back the element the internal pointer is onend()- Moves the internal pointer to the last elementextract()- Turns array entries into variables in the current symbol tablein_array()- Tells you whether a given value is in the arraykey()- Gives back the key at the internal pointer's positionkrsort()- Sorts an associative array by key, high to lowksort()- Sorts an associative array by key, low to highlist()- Assigns values from an array to several variables in one stepnatcasesort()- Sorts with a natural order algorithm, ignoring casenatsort()- Sorts with a natural order algorithmnext()- Moves the internal pointer forward one elementpos()- Another name forcurrent()prev()- Moves the internal pointer back one elementrange()- Builds an array from a range of elementsreset()- Moves the internal pointer to the first elementrsort()- Sorts an indexed array, high to lowshuffle()- Puts the elements in random ordersizeof()- Another name forcount()sort()- Sorts an indexed array, low to highuasort()- Sorts by value with a comparison function you write, keeping each key attached to its valueuksort()- Sorts by key with a comparison function you writeusort()- Sorts by value with a comparison function you write