note 102997 deleted from function.sort by danbrown
| From: | danbrown@php.net | Date: | Sat, 19 Mar 2011 15:25:19 +0000 |
| Subject: | note 102997 deleted from function.sort by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-178012@lists.php.net to get a copy of this message | ||
Note Submitter: ayalsule at gmail dot com
----
Sorting some numbers
<?php
/*
* Created By Ayham Alsuleman in 25\10\2010
*/
function NumberSort($array){
//check the inputs
if (is_array($array)){
//get array one by one
for ($i=0 ; $i < count($array) ; $i++){
//compare each value with other values in array
for ($j=$i+1;$j < count($array); $j++){
//if the current calue bigger than other one, then replace values
if ($array[$i] > $array[$j]){
//replacing
$tmp = $array[$i];
$array[$i] = $array[$j];
$array[$j] = $tmp;
}
}
}
return $array;
}else{
return false;
}
}
//Example
$array = array (2,3,54,56,4,4,23,6,7,100,23,5,63);
print '<pre>';
print_r(NumberSort($array));
print '</pre>';
?>