note 111781 deleted from function.ksort by aharvey

From: Date: Thu, 28 Mar 2013 17:51:00 +0000
Subject: note 111781 deleted from function.ksort by aharvey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-194252@lists.php.net to get a copy of this message
Note Submitter: seraphimg2 at gmail dot com ---- ksort wont help you at all if you want to sort an array with numerical keys. here's a custom function $dummy = array(3 => "sdfsd", 1 => "fsssd", 2 => "dgew"); foo($dummy); function foo ($dummy) { $test = array_keys($dummy); sort($test, SORT_NUMERIC); foreach($test as $key => $value) { foreach($dummy as $key2 => $value2) { if((int)$value === (int)$key2) { $result[$key2] = $value2; } } } } print_r($result); Array ( [1] => fsssd [2] => dgew [3] => sdfsd )

« previous php.notes (#194252) next »