hi, im new to php and was trying to do a sort on an array without using the predefined ones, everything else seems to be working except for this part..
was hoping you guys could help me out. thanks in advance..
<?php
$array1 = array(4,8,2,7,1);
$smallest;
//find smallest value in array
function findSmallest($array){
$size = count($array);
$GLOBALS['smallest'] = $array[0];
for($i = 0; $i < $size; $i++) {
if($GLOBALS['smallest'] > $array[$i+1]){
$GLOBALS['smallest'] = $array[$i+1];
}
//echo $GLOBALS['smallest'] . "<br>";
}
return $GLOBALS['smallest'];
}
findSmall($array1);
echo '<pre>';
var_dump($GLOBALS['smallest']);//returns null
echo '</pre>';
?>