note 124755 added to function.sort
| From: | Md.Abutaleb@php.net | Date: | Tue, 25 Feb 2020 12:28:23 +0000 |
| Subject: | note 124755 added to function.sort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-214219@lists.php.net to get a copy of this message | ||
<?php
/*
As I found the sort() function normally works as ascending order based on the following priority :
1. NULL
2. Empty
3. Boolean FALSE
4. String
5. Float
6. Int
7. Array
8. Object
Consider the following array:
*/
$a = ['fruit'=> 'apple', 'A' => 10, 20, 5, 2.5, 5=>'A
new value', 'last' => 'value', TRUE, NULL, "", FALSE, array(),
new StdClass];
sort($a);
var_dump($a);
#The output is:
array(13) {
[0]=>NULL
[1]=> string(0) ""
[2]=>bool(false)
[3]=>string(11) "A new value"
[4]=>string(5) "apple"
[5]=>string(5) "value"
[6]=> float(2.5)
[7]=> int(5)
[8]=>int(10)
[9]=>int(20)
[10]=>array(0) { }
[11]=> bool(true)
[12]=>object(stdClass)#1 (0) {}
}
//Hope it will remove your confusion when you're sorting an array with mix type data.
?>
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.195 (proxied: 182.160.98.85)
----
Manual Page -- http://php.net/manual/en/function.sort.php
Edit -- https://master.php.net/note/edit/124755
Del: integrated -- https://master.php.net/note/delete/124755/integrated
Del: useless -- https://master.php.net/note/delete/124755/useless
Del: bad code -- https://master.php.net/note/delete/124755/bad+code
Del: spam -- https://master.php.net/note/delete/124755/spam
Del: non-english -- https://master.php.net/note/delete/124755/non-english
Del: in docs -- https://master.php.net/note/delete/124755/in+docs
Del: other reasons-- https://master.php.net/note/delete/124755
Reject -- https://master.php.net/note/reject/124755
Search -- https://master.php.net/manage/user-notes.php