note 118638 added to function.natsort
| From: | bb7b5b9 at gmail dot com | Date: | Thu, 14 Jan 2016 08:07:05 +0000 |
| Subject: | note 118638 added to function.natsort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204665@lists.php.net to get a copy of this message | ||
This made me waste a lot of my precious youth ... natsort() is buggy if all numbers don't have
the same number of decimal places.
(php 5.6.4-4ubuntu6.2)
<?php
$different_decimal_places_in_values = array('D'=>'13.59', '14.6'
=> '14.6', 'C-' => '14.19');
natsort($a);
var_dump($a);
/*echoes
array(3) {
'D' =>
string(5) "13.59"
'14.6' =>
string(4) "14.6" <----------- badly ordered
'C-' =>
string(5) "14.19"
}*/
?>
While this
<?php
$same_num_decimal_places_in_values = array('D'=>'13.59', '14.6'
=> '14.60', 'C-' => '14.19'); natsort($a); var_dump($a);
/*echoes
array(3) {
'D' =>
string(5) "13.59"
'C-' =>
string(5) "14.19"
'14.6' =>
string(5) "14.60" <--------- that is the correct position
}
*/
?>
----
Server IP: 72.52.91.14
Probable Submitter: 74.73.133.158
----
Manual Page -- http://php.net/manual/en/function.natsort.php
Edit -- https://master.php.net/note/edit/118638
Del: integrated -- https://master.php.net/note/delete/118638/integrated
Del: useless -- https://master.php.net/note/delete/118638/useless
Del: bad code -- https://master.php.net/note/delete/118638/bad+code
Del: spam -- https://master.php.net/note/delete/118638/spam
Del: non-english -- https://master.php.net/note/delete/118638/non-english
Del: in docs -- https://master.php.net/note/delete/118638/in+docs
Del: other reasons-- https://master.php.net/note/delete/118638
Reject -- https://master.php.net/note/reject/118638
Search -- https://master.php.net/manage/user-notes.php