- Listing of String Functions
- Using the String Functions
- Formatting Strings
- Converting to and from Strings
- Creating Arrays
- Modifying Arrays
- Removing Array Elements
- Looping Over Arrays
- Listing of the Array Functions
- Sorting Arrays
- Navigating through Arrays
- Imploding and Exploding Arrays
- Extracting Variables from Arrays
- Merging and Splitting Arrays
- Comparing Arrays
- Manipulating the Data in Arrays
- Creating Multidimensional Arrays
- Looping Over Multidimensional Arrays
- Using the Array Operators
- Summary
Listing of the Array Functions
Just as it has many string functions, PHP also has many array functions. You can see a sample of them in Table 3-2.
Table 3-2. The Array Functions
Function Name |
Purpose |
array_chunk |
Splits an array into chunks |
array_combine |
Creates an array by using one array for the keys and another for the values |
array_count_values |
Counts the values in an array |
array_diff |
Computes the difference of arrays |
array_fill |
Fills an array with values |
array_intersect |
Computes the intersection of arrays |
array_key_exists |
Checks whether the given key or index exists in the array |
array_keys |
Returns the keys in an array |
array_merge |
Merges two or more arrays |
array_multisort |
Sorts multiple or multidimensional arrays |
array_pad |
Pads array to the specified length with a value |
array_pop |
Pops the element off the end of an array |
array_push |
Pushes one or more elements onto the end of array |
array_rand |
Picks one or more random elements out of an array |
array_reduce |
Reduces the array to a single value with a callback function |
array_reverse |
Returns an array with elements in reverse order |
array_search |
Searches the array for a given value and returns the corresponding key |
array_shift |
Shifts an element off the beginning of array |
array_slice |
Extracts a slice of the array |
array_sum |
Calculates the sum of values in an array |
array_unique |
Removes duplicate elements from an array |
array_unshift |
Adds one or more elements to the beginning of an array |
array_walk |
Calls a user-supplied function on every member of an array |
array |
Creates an array |
asort |
Sorts an array and maintains index association |
count |
Counts the elements in an array |
current |
Returns the current element in an array |
each |
Returns the current key and value pair from an array and advances the array cursor |
in_array |
Checks whether a value exists in an array |
key |
Gets a key from an associative array |
krsort |
Sorts an array by key in reverse order |
ksort |
Sorts an array by key |
list |
Assigns variables as if they were an array |
natcasesort |
Sorts an array using a case-insensitive "natural order" algorithm |
natsort |
Sorts an array using a "natural order" algorithm |
pos |
Alias of the current function |
reset |
Sets the pointer of an array to its first element |
rsort |
Sorts an array in reverse order |
shuffle |
Shuffles an array's elements |
sizeof |
Alias of the count function |
sort |
Sorts an array |
usort |
Sorts an array by values with a user-defined comparison function |
We'll see a number of the most important array functions in this chapter, such as those that let you sort the contents of an array, which are coming up next.