MemphiS Posted June 5, 2007 Share Posted June 5, 2007 $array = array("4","2","3","1"); sort($array); what i wish to do is check if the values in $array are in a incremental order. Anyone have a solution? Link to comment https://forums.phpfreaks.com/topic/54233-solved-counting-values/ Share on other sites More sharing options...
jitesh Posted June 5, 2007 Share Posted June 5, 2007 $array = array("4","2","3","1"); if(check($array)){ echo "Yes in incemental order"; }else{ echo "Not in incemental order"; } function check($array){ for($i=1;$i<count($array);$i++){ if($array[$i] < $array[$i-1]){ return false; } } return true; } Link to comment https://forums.phpfreaks.com/topic/54233-solved-counting-values/#findComment-268145 Share on other sites More sharing options...
MemphiS Posted June 5, 2007 Author Share Posted June 5, 2007 Thanks jitesh =) Link to comment https://forums.phpfreaks.com/topic/54233-solved-counting-values/#findComment-268148 Share on other sites More sharing options...
MemphiS Posted June 5, 2007 Author Share Posted June 5, 2007 hmm soo annoying.. Your example leaves out the first or last number which returns always false when it should be true or always true when it should be false.. Anyone else have a way of solving this? Link to comment https://forums.phpfreaks.com/topic/54233-solved-counting-values/#findComment-268217 Share on other sites More sharing options...
MemphiS Posted June 5, 2007 Author Share Posted June 5, 2007 err actually it is sort of what im looking for.. The only problem with it is that if there are two of the same numbers in the array it will return true. If 2 numbers are the same i wish for it to return false; Link to comment https://forums.phpfreaks.com/topic/54233-solved-counting-values/#findComment-268219 Share on other sites More sharing options...
MemphiS Posted June 5, 2007 Author Share Posted June 5, 2007 haha nevermind ive found the answer Link to comment https://forums.phpfreaks.com/topic/54233-solved-counting-values/#findComment-268222 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.