Array Functions Flashcards
Adding arrays (+)
Arrays will be added together and values with the same keys will be overwritten by subsequently added arrays.
array_change_key_case( array $array [, $case = CASE_LOWER] )
Returns an array with all keys from $array lowercased or uppercased. Numbered indices are left as is.
array_chunk( array $array, int $size [, bool $preserve_keys = false] )
Chunks an array into arrays with $size elements. That last chunk may contain less than $size elements.
array_column( array $input, mixed $column_key [, mixed $index_key = null ] )
$input should be a multi-dimensional array.
Returns the values from a single column of the $input, identified by the $column_key.
Optionally, an $index_key may be provided to index the values in the returned array by the values from the $index_key column of the input array.
array_combine( array $keys, array $values )
Creates an array by using the values from the $keys array as keys and the values from the $values array as the corresponding values.
array_count_values( array $array )
Returns the number of times each value in $array appears by returning an array in the form “$arrayValue” => “count”
array_diff( array $array1, array $array2 [, array $… ] )
Compares $array1 against one or more other arrays and returns the values in $array1 that are not present in any of the other arrays.
array_diff_assoc( array $array1, array $array2 [, array $…] )
Compares $array1 against $array2 and returns the difference.
Unlike array_diff() the array keys are also used in the comparison.
array_diff_key( array $array1, array $array2 [, array $…] )
Compares the keys from $array1 against the keys from $array2 and returns the difference.
This function is like array_diff() except the comparison is done on the keys instead of the values.
array_diff_uassoc( array $array2, array $array2 [, array $…], callable $key_compare_func )
Compares $array1 against $array2 and returns the difference. Unlike array_diff() the array keys are used in the comparison.
Unlike array_diff_assoc() a user supplied callback is used for the indices comparison, not internal function.
array_diff_ukey( array $array1, array $array2 [, array $…], callable $key_compare_func )
Compares the keys from $array1 against the keys from $array2 and returns the difference. This function is like array_diff() except the comparison is done on the keys instead of the values.
Unlike array_diff_key() a user supplied callback function is used for the indices comparison, not internal function.
array_fill( int $start_index, int $num, mixed $value )
Fills as array with $num entries of the value of the $value parameter, keys starting at the $start_index parameter.
array_fill_keys( array $keys, mixed $value )
Fills an array with the values of the $value parameter, using the values of the $keys array as keys.
array_filter( array $array [, callable $callback [, int flag = 0] ] )
Iterates over each value in the $array passing them to the $callback function.
If the $callback function returns true, the current value from $array is returned into the result array. Array keys are preserved.
array_flip( array $array )
Returns an array in flip order, i.e. keys from $array become values and values from $array become keys.
Note that the values of $array need to be valid keys, i.e. they need to be either integer or string. A warning will be emitted if a value has the wrong type, and the key/value pair in question will not be included in the result.
If a value has several occurrences, the latest key will be used as its value, and all others will be lost.
array_intersect( array $array1, array $array2 [, array $…] )
Returns an array containing all the values of $array1 that are present in all the arguments.
Keys are preserved.
array_intersect_assoc( array $array1, array $array2 [, array $…] )
Returns an array containing all the values of $array1 that are present in all the arguments.
The keys are also used in the comparison unlike in array_intersect()
array_intersect_key( array $array1, array $array2 [, array $…] )
Returns as array containing all the entries of $array1 which have keys that are present in all the arguments.
array_intersect_uassoc( array $array1, array $array2, [, array $…], callable $key_compare_func )
Returns an array containing all the values of $array1 that are present in all the arguments.
The keys are used in the comparison unlike in array_intersect()
array_intersect_ukey( array $array1, array $array2 [, array $…], callable $key_compare_func )
Returns an array containing all the values of $array1 which have matching keys that are present in all the arguments.
array_keys( array $input [, mixed $search_value] )
Returns an array of values containing the keys from $input.
If $search_value is specified, only keys corresponding to $input values of $search_value will be returned.
array_key_exists( mixed $key, array $source )
Returns a boolean based on the results of searching $source for a key of $key.
array_map( callable $callback, array $array1 [, array $…] )
Returns an array containing all the elements of $array1 after applying the $callback function to each one.
The number of parameters that the $callback function accepts should match the number of arrays passed to array_map()