★ wanayoo — archive 1999 http://www.php.net/manual/function.array-reverse.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Arrays
Quick Reference
German version of this pageJapanese version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
Arrays
* array
* array_count_values
* array_diff
* array_flip
* array_intersect
* array_keys
* array_merge
* array_merge_recursive
* array_multisort
* array_pad
* array_pop
* array_push
* array_rand
* array_reverse
* array_shift
* array_slice
* array_splice
* array_unique
* array_unshift
* array_values
* array_walk
* arsort
* asort
* compact
* count
* current
* each
* end
* extract
* in_array
* key
* krsort
* ksort
* list
* next
* pos
* prev
* range
* reset
* rsort
* shuffle
* sizeof
* sort
* uasort
* uksort
* usort
Manual: array_reverse
View the source code for this pageSearch the site



Previous page
 array_rand
 Updated
Mon, 07 Aug 2000
array_shift 
Next page


array_reverse

(PHP4 >= 4.0b4)

array_reverse --  Return an array with elements in reverse order

Description

array array_reverse (array array)

Array_reverse() takes input array and returns a new array with the order of the elements reversed.

Example 1. Array_reverse() example


$input = array ("php", 4.0, array ("green", "red"));
$result = array_reverse ($input);
      

This makes $result have array (array ("green", "red"), 4.0, "php").


User Contributed Notes: array_reverse


david@audiogalaxy.com
04-Mar-2000 12:40
With associative arrays array_reverse() keeps key => value pairs matched but reverses the order of the array as spaned by functions like each(). With numerical indexes array_reverse not only reverses position (as spaned by each) but also renumbers the keys. Both cases seem to be what people would generally want: indeed without the renumbering behavior, someone refering to array elements by numerical key wouldn't think array_reverse did anything. However, people who are trying to keep numerical keys associated with their values - e.g. trying to have holes in their arrays - will be foiled by the renumbering. The most telling results come from applying array_reverse() to arrays with mixed keys (some numbers and some strings). The strings stay attached and the rest of the keys get renumbered around them - most annoying if you are thinking what you've got is an associative array but some of your keys happen to be numbers.


david@audiogalaxy.com
04-Mar-2000 01:39
As a further clarification: key-value pairs have an order within an array completely separate from whatever the keys happen to be - the order in which you add them. This is the order that functions like each() and next() will move their pointer through the array. If you add to an array without specifying the key, like $array[] = value; then an internal counter supplies the key value and then the numerical order of your keys will be identical to the the internal order. If you "leave holes" - jumping ahead by specifying a higher number for the key, like $array[1000] = value; the internal counter gets pushed forward appropriately. Other than its effect on this internal counter, specifying a numerical key seems no different than specifying a string. However, some array functions, like array_merge() and array_reverse() treat keys that are numbers differently from keys that are not.


 About Notes


Previous page
 array_rand
 Updated
Mon, 07 Aug 2000
array_shift 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.