PHP/Data Structure/array reverse
Содержание
[убрать]array_reverse() function reverses the order of the array elements.
//The syntax is: array array_reverse(array array)
<?
$u = array ("A", "B", "C", "D");
$u = array_reverse ($u);
print_r($u);
?>
Concisely reversing a string by word
<?php
$reversed_s = implode(" ",array_reverse(explode(" ",$s)));
?>
Return an array with elements in reverse order
<?
$input = array ("php", 4.0, array ("green", "red"));
$result = array_reverse ($input);
?>
Reversing an Array Using array_reverse()
<?php
$dogs = array("A" => "C", "B" => "D", "X" => "Z", "Q" => "T");
array_reverse($dogs);
printf("<pre>%s</pre>\n", var_export($dogs, TRUE));
$nums = array(5, 2.2, -4, 2.3, 10);
array_reverse($nums);
printf("<pre>%s</pre>\n", var_export($nums, TRUE));
?>
Reversing a string by word
<?php
$s = "Once upon a time there was a turtle.";
$words = explode(" ",$s);
$words = array_reverse($words);
$s = implode(" ",$words);
print $s;
?>