note 62222 deleted from function.sort by cmb
| From: | cmb@php.net | Date: | Sun, 27 Oct 2019 08:38:05 +0000 |
| Subject: | note 62222 deleted from function.sort by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212795@lists.php.net to get a copy of this message | ||
Note Submitter: jerome a-t+ yamafoto d*o*t com
----
when sorting an array, beware of variable type from elements you put in this array
Example:
$a = 2; // $a is an integer
$b = 'item';
$arr = array($a, $b);
sort($arr);
print_r($arr);
this will output:
$arr[0] = 'item';
$arr[1] = 2;
$a = '2'; // $a is a string
$b = 'item';
$arr = array($a, $b);
sort($arr);
print_r($arr);
this will output:
$arr[0] = '2';
$arr[1] = 'item'
to avoid this problem use:
sort($arr, SORT_STRING)