note 68130 deleted from function.array-reverse by salathe

From: Date: Fri, 08 Jun 2012 20:08:15 +0000
Subject: note 68130 deleted from function.array-reverse by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-188504@lists.php.net to get a copy of this message
Note Submitter: Ella ---- You can also use array_reverse to reset array indexes without losing the order of the values. For example when you use unset() to delete values from an array, the value gets deleted but you end up with a missing index: $array[0] = 'record1'; $array[9] = 'record2'; $array[15] = 'record3'; Just use: $array = array_reverse(array_reverse($array)); And your indexes get rearranged: $array[0] = 'record1'; $array[1] = 'record2'; $array[2] = 'record3';

« previous php.notes (#188504) next »