note 32612 added to function.natsort

From: Date: Mon, 02 Jun 2003 23:41:48 +0000
Subject: note 32612 added to function.natsort
Groups: php.notes 
Request: Send a blank email to php-notes+get-49592@lists.php.net to get a copy of this message
Something that should probably be documented is the fact that both natsort and natcasesort maintain the key-value associations of the array. If you natsort a numerically indexed array, a for loop will not produce the sorted order; a foreach loop, however, will produce the sorted order, but the indices won't be in numeric order. If you want natsort and natcasesort to break the key-value associations, just use array_values on the sorted array, like so: natsort($arr); $arr = array_values($arr); ---- Manual Page -- http://www.php.net/manual/en/function.natsort.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32612 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32612&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32612&report=yes

« previous php.notes (#49592) next »