Jump to content

Output Error


doucettej3

Recommended Posts

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

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 :P

Link to comment
https://forums.phpfreaks.com/topic/134149-output-error/#findComment-698301
Share on other sites

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.