Using the link information for Coanda as a starting point, it is clear that PHP uses type manipulation when comparing objects of different types. The problem is understanding what rushes into that during the comparison, and I still could not find the complete list, but in general:
int
(int) string <,>,=, (int) int
0, ints . (). , .
PHP quicksort , , array[n/2], n - . , :
$pivot = $array[n/2] //n is the number of elements, this sets $pivot='img2'
//compare each element in the list (i am going to this by hand for demonstration)
(int) 'img2' < 2 //int to int comparison;'img2' resolves to 0 and 0 < 2
(int) 'img2' < 1 //int to int comparison;'img2' resolves to 0 and 0 < 1
'img2' > 'img1' // string to string comparison; strcmp is +256
'img2' > 'img 10' //string to string comparison; strcmp is +256
(float) 'img2' < 1.5 //float to float comparison;'img2' resolves to 0 and 0<1.5
'img2' > '3.14' //string to string comparison; strcmp is +54
'img2' > '2.72' //string to string comparison; strcmp is +55
( ).
$greater = array('img1', 'img10', '3.14', '2.72);
$less = array(2, 1, 1.5);
, 2 , . $greater , , .
sort($greater);
var_dump($greater);
array(4) {
[0]=>
string(5) "2.72"
[1]=>
string(4) "3.14"
[2]=>
string(4) "img1"
[3]=>
string(5) "img10"
}
, , . $lesser
$lesser = array(2, 1, 1.5);
sort($lesser);
var_dump($lesser);
array(3) {
[0]=>
int(1)
[1]=>
float(1.5)
[2]=>
int(2)
}
. , ( "img2" ). .
Array
(
[0] => 2.72
[1] => 3.14
[2] => img1
[3] => img10
[4] => img2
[5] => 1
[6] => 1.5
[7] => 2
)
, , $arr[3] .
$arr = array("img2", 1, "img1", 2, "img10", 1.5, "3.14", "2.72");
sort($arr);
var_dump($arr)
, int, float float.
array(8) {
[0]=>
string(4) "img1"
[1]=>
string(5) "img10"
[2]=>
string(4) "img2"
[3]=>
int(1)
[4]=>
float(1.5)
[5]=>
int(2)
[6]=>
string(4) "2.72"
[7]=>
string(4) "3.14"
}