quelle Posted June 19, 2011 Share Posted June 19, 2011 Im working on 2 functions which will check lowest and biggest value in array. So this code works fine, but only problem it isnt function <?php $brojevi = array(25, 14, 62); $mxm = $brojevi[0]; for ($i=0; $i < count($brojevi); $i++) { if($brojevi[$i]>$mxm) { $mxm = $brojevi[$i]; } } echo $mxm; ///////////////////////////////////////////////////// $brojevi = array(25, 14, 62); $mnm = $brojevi[0]; for ($i=0; $i < count($brojevi); $i++) { if($brojevi[$i]<$mnm) { $mnm = $brojevi[$i]; } } echo $mnm; ?> And now code which doesnt work - the functions part <?php //////////////////////////////////////////////////// function max($niz) { $mxm = $niz[0]; for ($i=0; $i < count($niz); $i++) { if($niz[$i]>$mxm) { $mxm = $niz[$i]; } } return $mxm; } //////////////////////////////////////////////////// function min($niz){ $mnm = $niz[0]; for ($i=0; $i < count($niz); $i++) { if($niz[$i]>$mnm) { $mnm = $niz[$i]; } } return $mnm; }; //////////////////////////////////////////////////// $jabuke = array(15, 25, 559, 554); $kruske = array(12, 9, 2, 44); max($jabuke); min($kruske); ?> I need this badly tommorow Link to comment https://forums.phpfreaks.com/topic/239819-function-min-max-problem/ Share on other sites More sharing options...
quelle Posted June 19, 2011 Author Share Posted June 19, 2011 nevermind, only problem was that min and max are already php selfmade functions Link to comment https://forums.phpfreaks.com/topic/239819-function-min-max-problem/#findComment-1231907 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.