Changes

Jump to: navigation, search

PHP Arrays

664 bytes added, 19:30, 1 June 2007
Sorting Associative Arrays
Associative arrays can be sorted in two ways, either by key or by value. To sort by key use ''ksort'' and ''krsort'' (reverse sort). To sort by value use the ''asort'' and ''arsort'' functions. The syntax and options for these functions are as outlined for the ''sort'' and ''rsort'' functions above.
 
== Getting Information About PHP Arrays ==
 
There are number of useful functions which can be used to obtain information about PHP arrays:
 
<table border="1" cellspacing="0">
<tr>
<th>Function<th>Description<th>
<tr>
<td>print_r<td>Prints the elements of an array to the output stream</td>
<tr>
<td>array_keys<td>Returns an array contaning all the keys in an associative array</td>
<tr>
<td>array_search<td>Returns the key for given value in the array if value exists</td>
<tr>
<td>array_values<td>Returns an array contaning all the values in an array</td>
<tr>
<td>in_array<td>Returns true ot false depneding on whether specified value is in array</td>
</table>

Navigation menu