- array_change_key_case – It converts the keys of an array into uppercase
- array_chunk – It splits an array into chunks
- array_combine – It creates an array by using one array for keys and another for its values
- array_count_values – It counts all the values of an array
- array_diff_assoc – It computes the difference of arrays with additional index check
- array_diff_key – It computes the difference of arrays using keys for comparison
- array_diff_uassoc – It computes the difference of arrays with additional index
- array_diff_ukey – It computes the difference of arrays using a callback function on the keys for comparison
- array_diff – It finds the difference of arrays
- array_fill_keys – It fills an array with values, specifying keys
- array_fill – It fills an array with the given values
- array_filter – It filters elements of an array using a callback function
- array_flip – It exchanges all keys with their associated values in an array
- array_intersect_assoc – It finds the intersection of arrays with additional index check
- array_intersect_key – It finds the intersection of arrays using keys for comparison
- array_intersect_uassoc – It finds the intersection of arrays with additional index check, compares indexes by a callback function
- array_intersect_ukey – It finds the intersection of arrays using a callback function on the keys for comparison
- array_intersect – It finds the intersection of arrays
- array_key_exists – It checks if the given key or index exists in the array
- array_keys – It returns all the keys or a subset of the keys of an array
- array_map – It applies the callback to the elements of the given arrays
- array_merge_recursive – It merges two or more arrays recursively
- array_merge – It merge arrays
- array_multisort – It sorts multiple or multi-dimensional arrays
- array_pad – It pads array to the specified length with a value
- array_pop – It pops the last element of an array
- array_product – It finds the product of values in an array
- array_push It pushes one or more elements onto the end of array
- array_rand – It fetches one or more random entries out of an array
- array_reduce – It reduce the array to a single value using a callback function
- array_replace_recursive – It replaces elements from passed arrays into the first array recursively
- array_replace – It replaces elements from passed arrays into the first array
- array_reverse – It returns an array with elements in reverse order
- array_search – It searches the array for a given value
- array_shift – It shift an element off the beginning of array
- array_slice – It extracts a slice of the array
- array_splice – It removes a portion of the array and replace it with something else
- array_sum – It finds the sum of values in an array
- array_udiff_assoc – It finds the difference of arrays with additional index check
- array_udiff_uassoc – It finds the difference of arrays with additional index check
- array_udiff – It finds the difference of arrays by using a callback function for data comparison
- array_uintersect_assoc – It finds the intersection of arrays with additional index check,
- array_uintersect_uassoc – It finds the intersection of arrays with additional index check, compares data and indexes by a callback functions
- array_uintersect – It finds the intersection of arrays, compares data by a callback function
- array_unique – It removes duplicate values from an array
- array_unshift – It prepend one or more elements to the beginning of an array
- array_values – It return all the values of an array
- array_walk_recursive – It applay a user function recursively to every member of an array
- array_walk – It apply a user function to every member of an array
- array – It can be used to create an array
- arsort – It sort an array in reverse order and maintain index association
- asort – It sort an array and maintain index association
- compact – it create array containing variables and their values
- count – It Count all elements in an array
- current – It returns the current element in an array
- each – It return the current key and value pair from an array
- end – It sets the internal pointer of an array to its last element
- extract – It import variables into the current symbol table from an array
- in_array It checks if a value exists in an array
- key – It fetches a key from an array
- krsort – It sorts an array by key in reverse order
- ksort – It sorts an array by key
- list – It assigns variables as if they were an array
- natcasesort – It sorts an array using a case insensitive “natural order” algorithm
- natsort – It sorts an array using a “natural order” algorithm
- next – It moves the internal array pointer of an array
- pos – It is an alias of current()
- prev – It rewinds the internal array pointer
- range – It can be used to create an array containing a range of elements
- reset – it set the internal pointer of an array to its first element
- rsort – It sorts the array in reverse order
- shuffle – It shuffles the array
- sizeof – It an alias of count()
- sort – It sorts the array
- uasort – It sorts an array with a user-defined comparison function and maintain index association
- uksort – It sorts an array by keys using a user-defined comparison function
- usort – It sorts an array by keys using a user-defined comparison function
Tag Archives: Array
check if value present in array – PHP
<?php
if(in_array(“val”,$array))
echo “Exists” ;
?>
if(in_array(“val”,$array))
echo “Exists” ;
?>
Fetch an element from the array randomly – PHP
<?php $testArray = array("value1", "value2", "value3", "value4"); $testRand = array_rand($testArray, 2); echo $testArray[$testRand[0]]; ?>
Sort the element of an array in reverse order – PHP
<?php $testArray = array("p", "c", "z", "a"); rsort($testArray); print_r($testArray); //Array ( [0] => z [1] => p [2] => c [3] => a ) ?>
Sort the element in an array – PHP
<?php $testArray = array("p", "c", "z", "a"); sort($testArray); print_r($testArray); //Array ( [0] => a [1] => c [2] => p [3] => z ) ?>
Function to add an element into an array – PHP
<?php $testArray = array("value1", "value2"); array_push($testArray, "value3", "value4"); print_r($testArray); //rray ( [0] => value1 [1] => value2 [2] => value3 [3] => value4 ) ?>
Search an element in an array and return the key – PHP
<?php $testArray = array(0 => 'value1', 1 => 'value4', 2 => 'value2', 3 => 'value3'); $key = array_search('value2', $testArray); // $key = 2; echo "Key is ".$key ; // 2 ?>
Find out the product of elements in an array – PHP
<?php $testArray = array(3, 2, 4, 7); echo "product is " . array_product($testArray); // product is 168 ?>
Function to replace array elements – PHP
<?php $testArray = array("orange", "banana", "apple", "raspberry"); $replaceArr1 = array(0 => "pineapple", 3 => "cherry"); $replaceArr2 = array(0 => "grape"); $basket = array_replace($testArray, $replaceArr1, $replaceArr2); print_r($basket); //Array ( [0] => grape [1] => banana [2] => apple [3] => cherry ) ?>
Find out the difference of arrays – PHP
<?php $testArray1 = array("key1" => "val1", "key2" => "val2", "val4"); $testArray2 = array("key4" => "val3", "val2", "val7"); $testArray3 = array_diff($testArray1, $testArray2); print_r($testArray3);// Array ( [key1] => val1 [0] => val4 ) ?>