It computes the difference of arrays with additional index check which is performed by a user supplied callback function
Example
<?php
function fun1($arg1, $arg2){
if ($arg1 === $arg2) return 0;
return ($arg1 > $arg2)? 1:-1;
}
echo “<pre>”;
$array1 = array(“a” => “PHP”, “b” => “ASP”, “c” => “JSP”, “VB”);
$array2 = array(“a” => “PHP”, “ASP”, “JSP”);
$array3 = array_diff_uassoc($array1, $array2, “fun1”);
print_r($array3);
?>
Output
Array
(
[b] => ASP
[c] => JSP
[0] => VB
)
It computes the difference of arrays using keys for comparison
Example
<?php
echo “<pre>”;
$array1 = array(‘JSP’ => 1, ‘PHP’ => 2, ‘ASP’ => 3);
$array2 = array(‘JAVA’ => 5, ‘VB’ => 6, ‘PHTML’ => 7);
print_r(array_diff_key($array1, $array2));
?>
Output
Array
(
[JSP] => 1
[PHP] => 2
[ASP] => 3
)
It computes the difference of arrays with additional index check
Example
<?php
echo “<pre>”;
$array1 = array(“a” => “PHP”, “b” => “JSP”, “c” => “ASP”, “red”);
$array2 = array(“a” => “green”, “yellow”, “red”);
$array3 = array_diff_assoc($array1, $array2);
print_r($array3);
?>
Output
Array
(
[a] => PHP
[b] => JSP
[c] => ASP
[0] => red
)
It counts all the values of an array
Example
<?php
echo “<pre>”;
$array = array(PHP, “ASP”, PHP, “ASP”, “PHP”);
print_r(array_count_values($array));
?>
Output
Array
(
[PHP] => 3
[ASP] => 2
)
It creates an array by using one array for keys and another for its values
Example
<?php
echo “<pre>”;
$array1 = array(‘PHP’, ‘ASP’, ‘JSP’);
$array2 = array(‘Javascript’, ‘VBScript’, ‘ActionScript’);
$array3 = array_combine($array1, $array2);
print_r($array3);
?>
Output
Array
(
[PHP] => Javascript
[ASP] => VBScript
[JSP] => ActionScript
)
It splits an array into chunks
Example
<?php
echo “<pre>”;
$array = array(‘a’, ‘b’, ‘c’, ‘d’, ‘e’);
print_r(array_chunk($array, 3));
?>
Output
Array
(
[0] => Array
(
[0] => a
[1] => b
[2] => c
)
[1] => Array
(
[0] => d
[1] => e
)
)
It converts the keys of an array into uppercase
Example
<?php
echo “<pre>”;
$array = array(“FirSt” => 17, “SecOnd” => 7);
print_r(array_change_key_case($array, CASE_UPPER));
?>
Output
Array
(
[FIRST] => 17
[SECOND] => 7
)
- 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
<?php
if(in_array(“val”,$array))
echo “Exists” ;
?>
<?php
$testArray = array("value1", "value2", "value3", "value4");
$testRand = array_rand($testArray, 2);
echo $testArray[$testRand[0]];
?>
Zend | Magento Certified PHP | eCommerce Architect