doucettej3 Posted November 25, 2008 Share Posted November 25, 2008 This code doesnt output at all. I cant figure out whats wrong with it. Any help would be greatly appreciated. function vac_week($avg_array, $fav_temp) { $k = 0; while($k < 52) { if($avg_array[$k] <= ($fav_temp + 10) && $avg_array[$k] >= ($fav_temp - 10)) { echo 'Your Ideal vacation week is week ' . $k; } else { $k++; } } } Link to comment https://forums.phpfreaks.com/topic/134149-output-error/ Share on other sites More sharing options...
jordanwb Posted November 25, 2008 Share Posted November 25, 2008 Nevermind. Link to comment https://forums.phpfreaks.com/topic/134149-output-error/#findComment-698300 Share on other sites More sharing options...
btherl Posted November 25, 2008 Share Posted November 25, 2008 You need to call the function like this: vac_week($array, $temp); I think you will also need to break out of the loop when the ideal vacation week is found (if you only want to find one), otherwise do the $k++ outside of the "else". Jordan: I saw your post before you edited, I will keep it secret Link to comment https://forums.phpfreaks.com/topic/134149-output-error/#findComment-698301 Share on other sites More sharing options...
premiso Posted November 25, 2008 Share Posted November 25, 2008 function vac_week($avg_array, $fav_temp) { $k = 0; while($k < 52) { if($avg_array[$k] <= ($fav_temp + 10) && $avg_array[$k] >= ($fav_temp - 10)) { echo 'Your Ideal vacation week is week ' . $k; } $k++; } } Infinite loop, if that condition is true the first time it will be true every time cause K was never incremented. Link to comment https://forums.phpfreaks.com/topic/134149-output-error/#findComment-698302 Share on other sites More sharing options...
jordanwb Posted November 25, 2008 Share Posted November 25, 2008 Jordan: I saw your post before you edited, I will keep it secret I was thinking "It can't be less than and greater than at the same time" then I noticed the +10 and -10. Link to comment https://forums.phpfreaks.com/topic/134149-output-error/#findComment-698305 Share on other sites More sharing options...
premiso Posted November 25, 2008 Share Posted November 25, 2008 I was thinking "It can't be less than and greater than at the same time" then I noticed the +10 and -10. Exactly =) EDIT: lol you edited it and now the above doesn't make sense. Anyhow I was saying exactly to since it was an infinite loop the data was never posted to the browser cause it never stopped to do so. Link to comment https://forums.phpfreaks.com/topic/134149-output-error/#findComment-698309 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.