note 4177 modified in array_reverse by ronabop

From: Date: Wed, 18 Oct 2000 04:28:57 +0000
Subject: note 4177 modified in array_reverse by ronabop
Groups: php.notes 
Request: Send a blank email to php-notes+get-6618@lists.php.net to get a copy of this message
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. http://www.php.net/manual/function.array-reverse.php

« previous php.notes (#6618) next »