note 111537 modified in function.asort by danbrown

From: Date: Mon, 04 Mar 2013 17:42:22 +0000
Subject: note 111537 modified in function.asort by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193808@lists.php.net to get a copy of this message
It is obviously necessary to log the keys used as so we don't overwrite previous entries in the array ;o) N.B. this also effects the timings, but still faster than the alternatives : * int : 0.00159 (ms) * str : 0.00092 (ms) <?php private function _keySort(Array $data) { $keys = array(); foreach($data as $row) { $keyIncrement = (!isset($keys[$row[$this->_orderField]])) ? $keys[$row[$this->_orderField]] = 0 : ++$keys[$row[$this->_orderField]]; $tempArray[$row[$this->_orderField].$keyIncrement] = $row; } if ($this->_orderDirection == 'DESC') { krsort($tempArray, SORT_NATURAL | SORT_FLAG_CASE ); } else { ksort($tempArray, SORT_NATURAL | SORT_FLAG_CASE); } return $tempArray; } ?> --was-- Update to previous post, it is obviously also necessary to log the keys used as so we don't overwrite previous entries in the array ;o) N.B. this also effects the timings, but still faster than the alternatives : * int : 0.00159 (ms) * str : 0.00092 (ms) <?php private function _keySort(Array $data) { $keys = array(); foreach($data as $row) { $keyIncrement = (!isset($keys[$row[$this->_orderField]])) ? $keys[$row[$this->_orderField]] = 0 : ++$keys[$row[$this->_orderField]]; $tempArray[$row[$this->_orderField].$keyIncrement] = $row; } if ($this->_orderDirection == 'DESC') { krsort($tempArray, SORT_NATURAL | SORT_FLAG_CASE ); } else { ksort($tempArray, SORT_NATURAL | SORT_FLAG_CASE); } return $tempArray; } ?> http://php.net/manual/en/function.asort.php

« previous php.notes (#193808) next »