PHP Array Functions Function array() Description Creates an array

array_change_key_case() Returns an array with all keys in lowercase or uppercase array_count_values() for each value array_chunk() array_combine() for its values array_diff() Returns an array with the number of occurrences Splits an array into chunks of arrays Creates an array by using one array for keys and another Compares array values, and returns the differences Fills an array with values Checks if the specified key exists in the array

array_fill(start,number,value) array_key_exists(key,array)

array_keys(array,value) Returns all the keys of an array array_merge() array_multisort() array_pad() lue, to an array array_pop() array_product() array_push() array_reverse() array_search() Merges one or more arrays into one array Sorts multiple or multi-dimensional arrays Inserts a specified number of items, with a specified va Deletes the last element of an array Calculates the product of the values in an array Inserts one or more elements to the end of an array Returns an array in the reverse order Searches an array for a given value and returns the key

arry_shift() Removes the first element from the arrat, and return the value of the removed element array_slice(array,start,len,pre) ay array_sum() array_unique() Returns selected parts of an arr

Returns the sum of the values in an array Removes duplicate values from an array

array_unshift() The array_unshift() function inserts new elements to an array. The new array values will be inserted in the beginning of the array. array_values() compact() es Returns all the values of an array Create array containing variables and their valu

Can be a string with the variable name. or an array of variab les..) var1: Required..count() object current() each() end() t extract() from an array in_array() key() krsort() ksort() list() next() prev() range() reset() st element rsort() shuffle() sizeof() sort() print_r() var_dump() Counts elements in an array. . Can be a string with the variable name. or properties in an Returns the current element in an array Returns the current key and value pair from an array Sets the internal pointer of an array to its last elemen Imports variables into the current symbol table Checks if a specified value exists in an array Fetches a key from an array Sorts an array by key in reverse order Sorts an array by key Assigns variables as if they were an array Advance the internal array pointer of an array Rewinds the internal array pointer Creates an array containing a range of elements Sets the internal pointer of an array to its fir Sorts an array in reverse order Shuffles an array Alias of count() Sorts an array print complete array content Alias of print_r() Compact: -----------Syntax: compact(var1. Multiple parameters are allowed. or an array of variab les var2: Optional.var2.

?> The output of the code above will be: Array ( [firstname] => Peter [lastname] => Griffin [age] => 38 ) . "location". "lastname". $lastname = "Griffin". ?> The output of the code above will be: Array ( [firstname] => Peter [lastname] => Griffin [age] => 38 ) Example 2 Using a string that does not match a variable. $result = compact($name. $name = array("firstname". "age"). $lastname = "Griffin". $age = "38". "age"). $age = "38". print_r($result). print_r($result).Example 1 <?php $firstname = "Peter". "lastname"). and an array of variable names: <?php $firstname = "Peter". $result = compact("firstname".

Sign up to vote on this title
UsefulNot useful