Jump to content

Archived

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

HookedOnWeb

Help with IF statements and the || and && conditions

Recommended Posts

I am trying to echo a when a range of number are between a starting and stopping number. For example:

When I is >= 12 and <=18 echo I

I am having trouble writing the conditional statement. Checking for one number is easy but when I try to check if the number is between two numbers, it cannot get it to work.

I am try:

$start = 12;
$end = 18;

for ($i=1; $i >= $start && $today <= $end; $1++) {
echo $i . "<br>";
}

What I want to happen is to print out are the numbers 12 - 18 down the screen.

I am using the FOR loop to test the condition. What I am really trying to do is add a IF condition to the code I have already written, for example:

if ($today >= $start && $today <= $end) {
echo "The range is between " . $i . "<br>";
}

This echo is just there for the example I am actually printing out something else, this way it was easier to read.

I know this is basic but I am learning.

Share this post


Link to post
Share on other sites
&& equals and

|| equals or



$start = 12;
$end = 18;

if(($today >= $start) && ($today <= $end)) {
echo "The range is between " . $i . "<br>";
}

hope it helps :D

Share this post


Link to post
Share on other sites

×

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.