Bug #3718: sort() and rsort() kill array keys

From: Date: Fri, 03 Mar 2000 10:35:57 +0000
Subject: Bug #3718: sort() and rsort() kill array keys
Groups: php.dev 
Request: Send a blank email to php-dev+get-16339@lists.php.net to get a copy of this message
From: stephan.beal@compaq.com Operating system: Linux 2.2.x with PHP 4B3 PHP version: 3.0.15 PHP Bug Type: Misbehaving function Bug description: sort() and rsort() kill array keys # PHP4B3. Haven't tried PHP3. $ar = array( "653434" => "Foo", "6452323" => "Bar", "9873" => "foobar" ); while( list( $k, $v ) = each( $ar ) ) { echo "$k --- $v<BR>\n"; } reset( $ar ); sort( $ar ); while( list( $k, $v ) = each( $ar ) ) { echo "$k --- $v<BR>\n"; } # The first one prints okay. # In the second one, the keys are reset to 0-2. # ksort does not do this (obviously), but there # is no rksort(), and I need to sort a list of files by # modification time (newest first). Suggestion? # I currently hold the files as an array, with the # filemtime() as the key. Also tried the names as the key, # and the filemtime() as the value, but then I lose the # key during a sort() or rsort(), anyway.

« previous php.dev (#16339) next »