PHP Array Functions

PHP Array Functions

The PHP Array Functions allow you to manipulate and access Arrays. PHP supports a lot of inbuilt functions which are very helpful. They support single and multi-dimensional arrays. These functions are a part of PHP core and there is no need to install them separately.

Learn about PHP Array Functions on Concatly!

Table of Contents

The PHP array_change_key_case is an inbuilt Function in PHP. It changes the keys of an array to upper or lowercase. In this article, we will discuss the PHP array_change_key_case Function. Also, we will discuss a few examples of using it. Syntax array array_change_key_case($array, $case = CASE_LOWER) Parameters The array_change_key_case Function ...
Read More
PHP array_chunk Function is an inbuilt function in PHP that splits an array into chunks. The input parameters specify the size of each chunk. However, depending on the size of an array, the last chunk may contain fewer elements. This function does not preserve keys by default. However, that can ...
Read More
The PHP array_column Function is an inbuilt function in PHP. It returns the values of a single column in a multi-dimensional array. It takes an Associative Array in input and returns an array containing column names. In this array, we will discuss the array_column function along with a few examples ...
Read More
PHP array_combine is an inbuilt Function in PHP. It generates a new array by combining keys and values of two arrays. The elements of the first array will be the keys to the new array. Similarly, the elements of the second array will be the values of the new array ...
Read More
PHP array_count_values is an inbuilt Function in PHP. It returns an associative array containing a count of values in an array. In other words, it is used to calculate the frequency of all elements in an array. In this article, we will discuss PHP array_count_values Function. Also, we will go ...
Read More
PHP array_diff Function is an inbuilt function in PHP which computes the difference between two or more arrays. It returns an array containing elements which exist in the first array but not in the subsequent arrays. In this article, we will discuss PHP array_diff Function along with common use cases ...
Read More
PHP array_diff_assoc Function is an inbuilt function in PHP which computes the difference between two or more arrays. Unlike array_diff Function, this function computes the difference taking both keys and values into account. It compares the keys and values in input arrays and returns an array containing elements present in ...
Read More
PHP array_diff_key Function is an inbuilt function in PHP which computes the difference between two or more arrays. Unlike array_diff Function, this function computes the difference taking only the keys for comparison. It compares the keys in input arrays and returns an array containing elements present in the first array and not ...
Read More
The PHP array_fill is an inbuilt Function in PHP. It fills an array with values. It basically creates a user-defined array with the given value. In this article, we will discuss the PHP array_fill Function along with examples. Syntax array_fill($startIndex, $numberOfElements, $values) Parameters The PHP array_fill Function expects three mandatory ...
Read More
The array_fill_keys is an inbuilt Function in PHP. It fills an array with values, also specifying the keys. Also, it works similarly to the PHP array_fill Function. In this article, we will discuss the PHP array_fill_keys Function. Also, we will discuss a few examples of using it. Syntax array array_fill_keys ...
Read More
PHP array_filter is an inbuilt function in PHP. It filters array elements using a callback function. It passes all elements of the array to a callback function. If the callback function returns false for a particular element, it deletes that element from the array. Also, it preserves the original keys ...
Read More
The PHP array_flip Function is an inbuilt function in PHP which exchanges the keys with their values in the associative array. It returns an array with the corresponding keys and values exchanged. However, the values of the existing array should be valid keys ie. either string or integer. The function ...
Read More
PHP array_intersect is an inbuilt function in PHP. It is used to compute the intersection of two arrays. It returns an array which contains elements present in all the input arrays. In this article, we will discuss the PHP array_intersect Function. Also, we will discuss a few examples of using ...
Read More
PHP array_intersect_assoc is an inbuilt function in PHP. It is used to compute intersection of two arrays. It returns an array which contains elements (both key and value) present in all the input arrays. On the other hand, the PHP array_intersect Function compares only array values and not the keys ...
Read More
PHP array_intersect_key is an inbuilt function in PHP. It is used to compute the intersection of two arrays. It returns an array which contains elements by comparing only keys present in all the input arrays. On the other hand, the PHP array_intersect Function compares only array values and not the ...
Read More
PHP array_key_exists is an inbuilt Function in PHP. It checks if a given key or index exists in an array or not. In this article, we will discuss the PHP array_key_exists Function. Also, we will discuss a few examples demonstrating it. We will also discuss the difference between PHP isset ...
Read More
PHP array_keys is an inbuilt Function in PHP which returns either all the keys or a subset of keys of an array. It takes an array in input and returns an array containing the keys of the array. In this article, we will discuss the PHP array_keys Function. Also, we ...
Read More
Using loops is one of the most basic concepts taught to a novice programmer. We always come up with a loop solution for any trivial task because we are accustomed to them. However, a more experienced programmer might write a solution without actually looping through the array using an inbuilt ...
Read More
PHP array_merge Function is an inbuilt Function in PHP which merges two or more arrays. This function merges elements in two or more arrays into one single array. While merging, it appends the elements of an array at the end of the previous array. In this article, we will learn ...
Read More
PHP array_merge_recursive is an inbuilt Function in PHP. It merges two or more arrays to a single array recursively. The function merges arrays in such a manner, that it appends the values of one array at the end of the previous array. Also, if there are the same keys in ...
Read More
PHP array_multisort is an inbuilt sort Function in PHP. It sorts multiple arrays at once or multi-dimensional arrays. Although it maintains string keys of an Associative Array, it re-indexes all the numerical keys. In this article, we will discuss the PHP array_multisort Function. Also, we will discuss a few examples ...
Read More
PHP array_pad is an inbuilt function in PHP. It returns an array of a specified length after padding it with a specific value. However, if the original size of the array is already greater than the specified length, it does not delete any elements. In this article, we will discuss ...
Read More
PHP array_pop Function is an inbuilt function in PHP which removes the last element from an array. It returns the last value of the array. Also, it decrements the size of the array by one. PHP array_pop Function works opposite to array_push function. In this article, we will discuss the ...
Read More
PHP array_product Function is an inbuilt Function in PHP which calculates the product of all elements in an array. It takes in an array containing integer or float values and returns the product of those elements. Though it is very simple to use, it helps in preventing a loop to ...
Read More
PHP array_push Function is an inbuilt function in PHP which inserts new elements in an array. It always inserts elements at the end of the array. The count of the array is also incremented by one. Moreover, multiple elements can be passed in the array_push function at once. In this ...
Read More
PHP array_rand is an inbuilt Function in PHP. It is used to pick one or more random keys from an array. On a practical basis, this is not that useful because the function uses a pseudo-random number generator that is not suitable for cryptographic purposes. In this article, we will ...
Read More
PHP array_reduce is an inbuilt function in PHP. This function reduces an array to a single value which can be an integer, float or string. It accepts a user-defined callback function. In this article, we will discuss the PHP array_reduce Function. Also, we will discuss a few examples of its ...
Read More
The array_reverse is an inbuilt Function in PHP which returns the reverse of input single or multi-dimensional array. Also, according to the parameters, it can also preserve the original keys of the array. In this article, we will discuss the PHP array_reverse Function along with a few examples. Syntax array ...
Read More
PHP array_search Function is an inbuilt function in PHP which searches a value in an array. It returns the corresponding key to the value. However, if the value is present more than once then it only returns the first occurrence. In this article, we will discuss the PHP array_search Function ...
Read More
PHP array_shift is an inbuilt Function in PHP. It removes an element from the beginning of the array and returns it. Also, if the keys of the array are numerical, it re-indexes the remaining elements again from 0. However, it does not change literal keys. In this article, we will ...
Read More
PHP array_slice Function is an inbuilt Function in PHP. It is used to fetch a part of an array by slicing through it. In this article, we will discuss the array_slice Function in PHP along with some examples. Syntax array_slice($array, $startPoint, $range, preserveKeys) Parameters The PHP array_slice Function consists of ...
Read More
PHP array_sum Function is an inbuilt Function in PHP. It calculates the sum of elements in an array. It takes in an array parameter and returns the sum of all values in the array. We will discuss the array_sum Function in PHP in this article. Also, we will discuss a ...
Read More
Many times we require an array not containing any duplicate values. PHP provides an inbuilt function for the same. The PHP array_unique Function removes duplicates from an array. If there are more than one duplicate value in an array, then the one appearing first is preserved. Note, that according to ...
Read More
PHP array_unshift is an inbuilt Function in PHP. It adds one or more elements in the beginning of an array. Also, it adds new elements starting with the 0 index. In this article, we will discuss the PHP array_unshift Function. Also, we will discuss a few examples of using it ...
Read More
PHP array_values is an inbuilt Function in PHP. It returns all the values of an array. It takes an array in the input and returns another array containing all the values in the array. However, it returns the array only up to the first level. In this article, we will ...
Read More
The PHP array_walk Function loops over every element of array and applies callback function to them, hence saving us the effort of writing extra loops. In this article, we will discuss the array_walk function. Also, we will discuss a few examples of using it. Array_walk function iterates over every element ...
Read More
PHP arsort is an inbuilt Function in PHP. It sorts arrays in descending order while maintaining the relationship between keys and values. The smallest element in the input array appears last and the largest appears first. Also, it provides six sorting types to change the sorting behavior. In this article, ...
Read More
PHP asort is an inbuilt Function in PHP. It sorts arrays in ascending order while maintaining the relationship between keys and values. The smallest element in the input array appears first and the largest appears last. Also, it provides six sorting types to change the sorting behavior. In this article, ...
Read More
PHP compact is an inbuilt Function in PHP. It creates an array from input variables. It creates an associative array whose key are variable name, and their corresponding value as array values. In this article, we will discuss the PHP compact Function. Also, we will discuss a few examples of ...
Read More
The count Function in PHP is one of the most used inbuilt functions. It returns the count of elements in an array in PHP. In this article, we will discuss the PHP count Function. Also, we will discuss a few examples to demonstrate its usage. PHP sizeof Function is an ...
Read More
PHP current is an inbuilt function in PHP. It returns the value which the internal pointer is currently pointing to in an array. However, it does not increment or decrement the current pointer after returning the value. In this article, we will discuss the PHP current Function. Syntax current ($array) ...
Read More
PHP end is an inbuilt function in PHP. It returns the last element of the array. Also, it sets the internal pointer to the last element of the array. It works opposite to PHP current Function. In this article, we will discuss the PHP end Function. Syntax end ($array) Parameters ...
Read More
PHP explode Function is an inbuilt string function of PHP. Explode literally means to break down. The Function splits or breaks a string into an array of strings. It returns an array containing exploded sub-strings of the string. Sub-strings form by splitting the string by given string delimiter. In this ...
Read More
PHP extract is an inbuilt function in PHP. It performs array to variable conversion. In other words, it converts array keys of an associative array to variable names, and the corresponding values to value of the variable. In this article, we will discuss the PHP extract Function. Also, we will ...
Read More
PHP implode Function is an inbuilt function of PHP. It joins elements of an array into a single string. It returns a string containing elements of the array. In this article, we discuss the PHP implode Function. Also, we will discuss a few examples demonstrating the usage of this function ...
Read More
The in_array Function is an inbuilt Function in PHP. It is used to check whether an element exists in an array or not. It is one of the most used functions in PHP. In this article, we will discuss the PHP in_array Function. Also, we will discuss a few examples ...
Read More
PHP join Function is an inbuilt function of PHP. It joins elements of an array into a single string. It returns a string containing elements of the array. In this article, we discuss the PHP join Function. Also, we will discuss a few examples demonstrating the usage of this function ...
Read More
JSON stands for JavaScript Object Notation. It is a lightweight format to store and transport data. PHP supports the use of JSON strings by default. In this article, we will discuss PHP JSON Functions to encode and decode objects to a JSON string. Sample JSON A sample JSON string looks ...
Read More
The PHP json_decode is an inbuilt Function in PHP that converts a JSON String to PHP Object. For example, it can convert a JSON String to an array in PHP. In this article, we will discuss the PHP json_decode Function. Also, we will discuss a few examples of using it ...
Read More
The PHP json_encode is an inbuilt Function in PHP that returns a JSON representation of the input value. For example, it can create a convert a PHP array to JSON String. In this article, we will discuss the PHP json_encode Function. Also, we will discuss a few examples of using ...
Read More
PHP krsort is an inbuilt Function in PHP. It sorts arrays in descending order according to keys while maintaining the relationship between keys and values. The smallest key in the input array appears last and the largest appears first. In this article, we will discuss the PHP krsort Function. Also, ...
Read More
PHP ksort is an inbuilt Function in PHP. It sorts arrays in ascending order according to keys while maintaining the relationship between keys and values. The smallest key in the input array appears first and the largest appears last. In this article, we will discuss the PHP ksort Function. Also, ...
Read More
Multidimensional Arrays in PHP are a type of arrays which store another array in each index rather than a single element. In other words, it is an array of arrays. Therefore, every element of the array may contain an element or another sub-array and so on. Also, we require more ...
Read More
PHP natcasesort is an inbuilt function in PHP. It sorts an array using natural order algorithm in a case-insensitive manner. The sorting is done in a way a normal human will sort the array. Also, it does not check for the type of value for comparison. For example, in string ...
Read More
PHP natsort is an inbuilt function in PHP. It sorts an array using natural order algorithm which is how a normal human being would sort the array. Therefore, it does not check for the type of value for comparison. For example, in string representation 40 is less than 8 in ...
Read More
PHP next is an inbuilt function in PHP. It moves the internal pointer to the immediate next element to the current element of the array. In this article, we will discuss the PHP next Function. Syntax next ($array) Parameters The function expects only one parameter. The input array is passed ...
Read More
PHP prev is an inbuilt function in PHP. It moves the internal pointer to the immediate previous element to the current element of the array. In this article, we will discuss the PHP prev Function. Syntax prev ($array) Parameters The function expects only one parameter. The input array is passed ...
Read More
PHP range is an inbuilt Function in PHP. It creates an array containing a range of elements of any kind such as integer or alphabets. It creates an array within the input range (from low to high). In this article, we will discuss the PHP range Function. Also, we will ...
Read More
PHP reset is an inbuilt Function in PHP. It returns the first element of the array. Also, it sets the internal pointer to the first element of the array. It works opposite to PHP end Function. In this article, we will discuss the PHP reset Function. Syntax reset ($array) Parameters ...
Read More
PHP rsort is an inbuilt function in PHP. It sorts an array in descending order i.e, from bigger to smaller element. Also, it makes the changes in the original array itself. The function provides 6 sorting types to sort an input array. In this article, we will discuss the PHP ...
Read More
PHP shuffle is an inbuilt Function in PHP. It shuffles an input array in randomized order using a pseudo number generator. However, it is not suitable for cryptographic purposes. In this article, we will discuss the PHP shuffle Function along with some examples. Also, we will discuss a way to ...
Read More
The sizeof Function in PHP returns the count of elements in an array in PHP. Also, it is an alias of the count Function. In this article, we will discuss the PHP sizeof Function. Also, we will discuss a few examples to demonstrate its usage. Syntax integer sizeof($array, $mode = ...
Read More
PHP sort is an inbuilt function in PHP. It sorts an array in ascending order i.e, from smaller to bigger element. Also, it makes the changes in the original array itself. The function provides 6 sorting types to sort an input array. In this article, we will discuss the PHP ...
Read More
The PHP strpbrk is an inbuilt function in PHP. It searches a string for a set of characters and returns the section of the string from which it found any one of the characters. However, if any character does not exist in the function, it returns false. Also, the function ...
Read More
PHP uasort is an inbuilt Function in PHP. It sorts an associative array by value using a user-defined callback function. It is very useful if we want to sort an array in a custom manner. However, unlike usort, this function preserves the original keys of the array. In this article, ...
Read More
PHP uksort is an inbuilt Function in PHP. It sorts an associative array by key using a user-defined callback function. It is very useful if we want to sort an array in a custom manner. However, unlike usort, this function preserves the original keys of the array. In this article, ...
Read More
PHP usort is an inbuilt Function in PHP. It sorts an array by value using a user-defined callback function. It is very useful if we want to sort an array in a custom manner. However, the function assigns new keys to the elements present after sorting. In this article, we ...
Read More
PHP provides multiple inbuilt functions for Sorting Arrays in PHP. In this article, we will list different sorting functions in PHP. Each and every function is useful in a different way. Also, every function is minutely different from the other. The main points of differences are: Some sorting functions sort ...
Read More