View Full Version : Comparing numbers differently

05-18-2011, 01:06 PM
I spent several hours searching on how I can compare numbers

ex : 5-6-8-7 with 6-7-5-8

the results should be the same since the numbers are the same. My logic is to sort first the number then compare it. can anyone help me on how to sort this number that has dash on it ?

Got this from the net but I dont know how to pass the numbers to the array without hard cording it. Assuming this will be inputted on form.

$array = array(5, 6, 8, 7);
natsort($array); // Sorts from highest to lowest
for ($i = 0; $i < 4; $i++)
echo $array[$i];

05-18-2011, 01:30 PM
Try this test script


// this creates an array, separating the string by dashes.

// reverse sort;

foreach($numbers as $number){
echo "$number <br>";