note 107228 added to function.ksort
| From: | geompse at gmail dot com | Date: | Mon, 23 Jan 2012 10:43:03 +0000 |
| Subject: | note 107228 added to function.ksort | ||
| Groups: | php.notes php.notes | ||
| Request: | Send a blank email to php-notes+get-185710@lists.php.net to get a copy of this message | ||
This function is very usefull, but be aware that it will convert float keys to int (reproduced on
PHP 5.3.9).
To bypass this behavior, either use "uksort" or use a multiplier (0.2*100 = 20 : not a
float ;).
Ex :
<?php
$distances = array(
0.2=>array(
'Paris',
),
5.3=>array(
'Choisy-le-Roi',
'Creteil',
),
1.4=>array(
'Ivry-sur-Seine',
),
);
ksort($distances);
print_r($distances);
?>
Will output :
Array
(
[0] => Array
(
[0] => Paris
)
[1] => Array
(
[0] => Ivry-sur-Seine
)
[5] => Array
(
[0] => Choisy-le-Roi
[1] => Creteil
)
)
----
Server IP: 89.31.146.176
Probable Submitter: 82.227.124.74
----
Manual Page -- http://www.php.net/manual/en/function.ksort.php
Edit -- https://master.php.net/note/edit/107228
Del: integrated -- https://master.php.net/note/delete/107228/integrated
Del: useless -- https://master.php.net/note/delete/107228/useless
Del: bad code -- https://master.php.net/note/delete/107228/bad+code
Del: spam -- https://master.php.net/note/delete/107228/spam
Del: non-english -- https://master.php.net/note/delete/107228/non-english
Del: in docs -- https://master.php.net/note/delete/107228/in+docs
Del: other reasons-- https://master.php.net/note/delete/107228
Reject -- https://master.php.net/note/reject/107228
Search -- https://master.php.net/manage/user-notes.php