Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

//print out all the values
foreach($numbers as $value)
{
print("$value
\n");
}
?>


sizeof


This is an alias for the count function.


sort(array unsorted_array)


The sort function sorts an array by element values from lowest to highest. If any element
is a string, all elements will be converted to strings for the purpose of comparison, which
will be made alphabetically. If all elements are numbers, they will be sorted numerically.
Like rsort, sort discards key values and reassigns elements with key values starting at
zero. Chapter 15 discusses sorting in depth.


<?
//create test data
$colors = array("one"=>"orange", "two"=>"cyan",
"three"=>"purple");


//sort and discard keys
sort($colors);


//show array
foreach($colors as $key=>$value)
{
print("$key = $value
\n");
}
?>


uasort(array unsorted_array, string comparison_function)


The uasort function sorts an array using a custom comparison function. The index
values, or keys, move along with the element values, similar to the behavior of the asort
function.


The comparison function must return a signed integer. If it returns zero, then two
elements are considered equal. If a negative number is returned, the two elements are
considered to be in order. If a positive number is returned, the two elements are
considered to be out of order.

Free download pdf