Liodel Posted June 26, 2008 Share Posted June 26, 2008 My problem is, how do i sort an array with int values only, without using sort() function. The given are: - array which contains int values ex. (7, 8, 3, 1, 5) Not given: - the actual values of the array - the length of the array I have already written something to know the least value, but putting it all together sorted in a new array is my problem. This is the code so far: <?php $a = array(8, 3, 6, 2, 1); // this is just a sample value for the code to test $a_len = count($a); $pointer = 0; for ($i = 0; $i < $a_len; $i++) { if (!($a[$pointer] <= $a[$i])) { $pointer++; $i = 0; } } $b[] = $a[$pointer]; foreach ($b as $b2) echo $b2; ?> Thanks for helping. Link to comment https://forums.phpfreaks.com/topic/111970-sorting-array-wo-sort/ Share on other sites More sharing options...
kenrbnsn Posted June 26, 2008 Share Posted June 26, 2008 Why don't you want to use the built in sort function? This sounds like a homework assignment. You should take a look at Sorting Algorithms. Ken Link to comment https://forums.phpfreaks.com/topic/111970-sorting-array-wo-sort/#findComment-574724 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.