We can sort of array value through sort() function but if interviewer ask without this function create own function then its very easy.
Example:- array(1, 5, 6, 3, 2, 4, 7, 10, 8, 9) should be array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
<?php
$arr = array(1, 5, 6, 3, 2, 4, 7, 10, 8, 9);
$arr_count = count($arr);
for ($i = 1; $i < $arr_count; $i++) {
for ($j = $i; $j > 0; $j--) {
if ($arr[$j] < $arr[$j - 1]) {
$temp = $arr[$j];
$arr[$j] = $arr[$j - 1];
$arr[$j - 1] = $temp;
}
}
}
?>
Output:- Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 )