Core PHP

Array Processing Functions

Array Processing Functions
array_change_key_case()
array array_change_key_case(array $qaArray, int $iCase = CASE_LOWER)
This function returns the same array as $qaArray with the letters of the keys all switched to uppercase or lowercase, depending on the value of $iCase: CASE_LOWER or CASE_UPPER. If the value passed in as $qaArray is not an array, then the function returns null. Also, it throws E_WARNING, if the $qaArray is not an array and returns null. If two key, say "name" and "Name", would be made equivalent, by this function, the latter instance and all others are changed into integer keys in a manner similar to an insert and later integer indices may be changed.
Argument Description
array $qaArray This is the array that will have its keys or indices changed.
int $iCase This integer designates whether the keys will be made uppercase or lowercase. For example, if "Name" is a key, the value CASE_UPPER will change it to "NAME" and the value CASE_LOWER will change it to "name".
array_chunk()
array array_chunk(array $qaArray, int $iLength, bool bPreserveKeys = false)
This function splits an array of elements into an array of smaller arrays of $iLength elements or less, in the case of the last array. If $iLength is less than 1, E_WARNING is thrown and null is returned.
Argument Description
array $qaArray This is the array of elements that will be split into smaller arrays.
int $iLength This is the length of the smaller arrays, except, possibly, for the last one.
bool bPreserveKeys This determines whether the key or indices of the smaller arrays should be the same as those of the original array.
array_column()
array array_column(array $qaaMultiArray, int|string|null $xKeyOfColumn, int|string|null $xKeyOfValueAsKey = null)
This function returns an array of the values of column of the two dimensional array $qaaMultiArray. That is, it runs over the arrays at each entry of $qaaMultiArray and takes the entry at the key value of $xKeyOfColumn. Additionally, $xKeyOfValueAsKey can be set to specify the key for the resulting array via the columns values of $qaaMultiArray at $xKeyOfValueAsKey.
Argument Description
array $qaaMultiArray This is the two dimensional array of elements that we will take a column of to generate the returned array.
int|string|null $xKeyOfColumn This the key of that is used to select the entries that generate the resulting array.
int|string|null $xKeyOfValueAsKey This is an optional argument that can be used to specify the keys for the returned array as values of a column of $qaaMultiArray.
array_combine()
array array_combine(array $qaKeys, array $qaValues)
This function returns an array of an entries with $qaKeys as its keys and $qaValues as its values. If the arrays $qaKeys and $qaValues are not the same size, the function throws E_WARNING and returns false.
Argument Description
array $qaKeys These are the keys of the returned array.
array $qaValues These are the values of the returned array.
array_count_values()
array array_count_values(array $qaArray)
This function returns an array that uses the values of $qaArray as its keys with the associated values equal to the integer multiplicity of the value in the original array. The function throws E_WARNING for every element that is not an integer or a string.
Argument Description
array $qaArray This is the array for which the multiplicities of its values are counted..
array_fill()
array array_fill(int $iStart, int $iCount, various $qValue)
This function returns an array of entries with numerical keys from $iStart to ($iStart + $iCount - 1) and with the value of $qValue. The function throws E_WARNING if $iCount is negative.
Argument Description
int $iStart This is the starting key for the returned array
int $iCount This is the number of entries in the returned array.
various $qValue This is the value of all of the entries of the returned array.
array_fill_keys()
array array_fill_keys(array $qaKeyArray, various $qValue)
This function returns an array of entries with keys from $qaKeyArray and the value of $qValue.
Argument Description
array $qaKeyArray This array determines the keys of the returned array
various $qValue This is the value of all of the entries of the returned array.
array_filter()
array array_filter(array $qaArray, function|null $fnFilter = null, int $iMode = 0)
This function returns an array of all of the entries of $qaArray that return true when passed into the function $fnFilter. The keys are preserved from the original array. The value of $iMode specifies whether the values, keys, or both are passed into the filter function.
Argument Description
array $qaArray This is the array that contains entries that will be returned in the array, along with their associated keys.
function|null $fnFilter This is the filter function that returns true or false.
int $iMode This determines whether the value, key, or both are passed into the filter function via the values 0, ARRAY_FILTER_USE_KEY, or ARRAY_FILTER_USE_BOTH, respectively. When both are passed into the filter function, the value is the first argument and the key is the second argument.
array_flip()
array array_flip(array $qaArray)
This function returns an array of all of the entries of $qaArray with the keys and values interchanged. If the values of $qaArray are not valid keys, that is are not strings or ints, then null is returned to signal failure and E_WARNING is thrown. If a value appears multiple times in the original array, then only the last version will be kept, as each new key will overwrite the previous ones.
Argument Description
array $qaArray This is the array that contains entries that will be returned in the array, but with flipped values and keys.
array_keys()
array array_keys(array $qaArray)
array array_keys(array $qaArray, various $qSearchValue, bool $bStrictEquality = false)
This function is overloaded with two versions. This function returns an array of the keys of $qaArray as its values. The keys of the new array are sequential integers. The search value $qSearchValue can be used to specify that the keys are only return for this value. The boolean $bStrictEquality can be used to specify that the search value is compared with the === operator.
Argument Description
array $qaArray This is the array from which the keys are being taken.
various $qSearchValue If used, this is the value that we are matching for selecting the keys.
bool $bStrictEquality If used, this search value is compared with the stricter === operator.
array_map()
array array_map(function|null $fnConverter, array $qaArray, ...)
This function returns an array of all of the values of $qaArray and any additional arrays with the function $fnConverter appplied to the values. If only one array is passed in, the keys are preserved. Otherwise, the keys are successive integers. if $fnConverter is null, the values are returned just as they were passed in.
Argument Description
function|null $fnConverter This a function that converts the values of the arrays.
array $qaArray The values of this array are converted via $fnConverter before they are returned. More than on array may be passed into the function.
array_merge()
array array_merge(array $qaArray, ...)
This function merges the elements of a set of arrays into one array and returns that result. The entries from each array will be appended successively. If multiple arrays have the same string key, the last value will overwrite the earlier ones. However, number keys will not overwrite each other.
Argument Description
array $qaArray, ... These are the arrays that are to be merged. There can be any number of arrays passed in as arguments
array_merge_recursive()
array array_merge_recursive(array $qaArray, ...)
This function merges the elements of a set of arrays into one array and returns that result. The entries from each array will be appended successively. If multiple arrays have the same string key, the entries will be merged as arrays into the entry for that key. However, number keys will not be merged with each other overwrite each other, but, rather, the values will be appended.
Argument Description
array $qaArray, ... These are the arrays that are to be merged. There can be any number of arrays passed in as arguments.
array_pad()
array array_pad(array $qaArray, int $iLength, various $qPadValue)
This function returns the array $qaArray with additional copies of $qPadValue added on to it to extend the length to absolute value of $iLength. If the absolute value of $iLength is less than the length of $qaArray, then no padding is done and and an exact copy of $qaArray is returned. Otherwise, the array is padded on the front if $iLength is negative and on the back if $iLength is positive.
Argument Description
array $qaArray This is the array that is to be padded.
int $iLength This is the length of the padded array that is returned.
various $qPadValue This is the value that is copied to pad the array.
array_replace()
array array_replace(array $qaArray, array $qaReplacement1, ...)
This function returns an array with all of the values of $qaArray replaced by the value of the last replacement array that has a value with the same key.
Argument Description
array $qaArray The array that has values that are to be replaced by those with matching keys.
array $qaReplacement1, ... This is a set of one or more arrays that will be used to replace values for the returned array.
array_replace_recursive()
array array_replace_recursive(array $qaArray, array $qaReplacement1, ...)
This function returns an array with all of the values of $qaArray replaced by the value of the last replacement array that has a value with the same key. If both $qaArray and the replacement array have values that are arrays for the same key, the function is called recursively on these arrays.
Argument Description
array $qaArray The array that has values that are to be replaced by those with matching keys.
array $qaReplacement1, ... This is a set of one or more arrays that will be used to replace values for the returned array.
array_reverse()
array array_reverse(array $qaArray, bool $bPreserveNumericKeys = false)
This function returns a copy of array $qaArray with the order of the entries reversed. If $bPreserveNumericKeys is true, the array will be indexed just as it was, but the keys will count down instead of up. Otherwise, the last entry will be given the index 0 and so on. String keys are always preserved.
Argument Description
array $qaArray The array that is to be reversed.
bool $bPreserveNumericKeys Set this to true to preserve the numeric keys for each value.
array_slice()
array array_slice(array $qaArray, int $iStart, int|null $iLength = null, bool $bPreserveNumericKeys = false)
This function returns an array filled with $iLength entries of the array $qaArray, starting at the index $iStart. If $iStart is negative, the entries will be taken from the end of the array, rather than the beginning. If $iLength is null, all of the remaining entries after the start will be included. If $iLength is negative, the subarray will stop at the absolute value of that many from the end of the array. If $bPreserveNumericKeys is true, the numeric keys will be the same as they were in the original array.
Argument Description
array $qaArray The array from which the returned array is taken.
int $iStart The index of $qaArray that determines the first entry that is taken for the returned array.
int|null $iLength The length of the returned array.
bool $bPreserveNumericKeys This value determines whether to old numeric keys will be used in the returned array.
array_splice()
array array_splice(array $qaArray, int $iStart, int|null $iLength = null, various $qReplacementArrayOrValue = [])
This function returns the array $qaArray with a portion of $iLength entries starting at the index $iStart replaced by the value or values specified by $qReplacementArrayOrValue. If $iStart is negative, the entries will be taken from the end of the array, rather than the beginning. If $iLength is null, all of the remaining entries after the start value will be included. If $iLength is negative, the removal will stop at the absolute value of that many from the end of the array.
Argument Description
array $qaArray The array from which the returned array is taken.
int $iStart The index of $qaArray that determines the first entry of the replacement.
int|null $iLength The length of the array that is removed.
various $qReplacementArrayOrValue This replaces the specified slice that was cut from the array. If nothing was cut, this is simply an insertion. It can be an array or a single element.
array_unique()
array array_unique(array $qaArray, int $iComparison = SORT_STRING)
This function returns an array of the entries of the array $qaArray with all of the repeated values of the array removed, as determined by the comparision $iComparison.
Argument Description
array $qaArray This is the array from which the returned array entries are taken.
int $iComparison This specifies the comparison for determining uniqueness:
  • SORT_REGULAR - Compare the values without changing their types
  • SORT_NUMERIC - Compare the values numerically
  • SORT_STRING - Compare the values as strings
  • SORT_LOCALE_STRING - Compare the values as strings according to the current locale
array_values()
array array_values(array $qaArray)
This function returns an array of all of the values in the array $qaArray. However, all of the entries of the returned array have numerical keys.
Argument Description
array $qaArray This is the array from which the values of the returned array will be taken.
compact()
array compact(array|string $qVarNameKey1, ...)
This function returns an array with the variable names as keys and the values of the variables as the corresponding values for the returned array. The function throws E_NOTICE, if a string refers to an unset variable.
Argument Description
array|string $qVarNameKey1, ... This is the set of variables from which the array will be constructed.
range()
array range(string|int|float $xStart, string|int|float $xEnd, int|float $xStep = 1)
This function creates and returns an array of elements starting with the value $xStart and ending with the value $xEnd, using $xStep as the increment.
Argument Description
string|int|float $xStart This is the first value of the returned array.
string|int|float $xEnd This is the last value of the returned array.
int|float $xStep This is the increment value of successive values of the returned array.
 
 

© 2007–2024 XoaX.net LLC. All rights reserved.