//print out all the values
//(red, blue, green, purple, yellow)
print("
");\n".);
print_r($colors);
print("
?>
array array_reverse(array data)
The array_reverse function returns the data argument with the elements in reverse
order. The elements are not sorted in any way. They are simply in the opposite order.
<?
//create test data
$data = array(3, 1, 2, 7, 5);
//reverse order
$data = array_reverse($data);
//print in reverse order
//5, 7, 2, 1, 3
print("
");\n");
print_r($data);
print("
?>
value array_shift(array stack)
The array_shift function returns the first element of an array, removing it as well. This
allows you to treat the array like a stack. The array_unshift function adds an element
to the beginning of an array. Use array_pop and array_push to perform the same
actions with the end of the array.
<?
//set up an array of color names
$colors = array("red", "blue", "green");
$firstColor = array_shift($colors);
//print "red"
print($firstColor. "
\n");
//dump colors (blue, green)
print("
");\n");
print_r($colors);
print("
?>