[Php]
<? Php
// Select sorting
// Sort data in ascending order
// Date_default_timezone_set ('aisa/Shanghai ');
$ Select = array ();
For ($ I = 0; I I <500; $ I ++)
{
$ Select [$ I] = rand (0,3000 );
}
Function selectsort (& $ arr)
{
$ Temp = 0;
For ($ I = 0; $ I <count ($ arr)-1; $ I ++)
{
$ Minval = $ arr [$ I]; // each time you think that the number of I is the minimum value
$ Minindex = $ I;
For ($ j = $ I + 1; $ j <count ($ arr); $ j ++)
{
// The current value is not the minimum value.
If ($ minval> $ arr [$ j])
{
$ Minval = $ arr [$ j];
$ Minindex = $ j;
}
}
// Exchange after the inner for loop ends. This is the place where the Bubble Sorting is superior.
$ Temp = $ arr [$ I];
$ Arr [$ I] = $ arr [$ minindex];
$ Arr [$ minindex] = $ temp;
}
}
Selectsort ($ select );
Print_r ($ select );
// Date_default_timezone_set ('aisa/Shanghai ');
?>
[Php]