Help with PHP conditional please

I’m getting a syntax error at the modulus 3 or 5 statement. I’m really stuck. Any help would be great!


 ($num1 % 3 == 0){
       print  " Holiday   \r\n ";
    }
       else if ( $num1 % 5 == 0){
            print  " Presents  \r\n ";
    }
          if ($num1 ==  % 3 || % 5){
               print "$num1 is modulus 3 or 5"
    }                 
                print " $num1 \r\n ";
    }

welcome @collypride to the forum

most of your code is correct, but in this instruction:

if ($num1 == % 3 || % 5) 

you are checking if $num is divisible of 3 or divisible of 5, so your code should be like this :

if($num1 % 3 == 0 || $num1 % 5 == 0)

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Hello and welcome to the forum :partying_face:!

Besides what @AbdelliNasredine said, you’re missing a semi-colon:

print "$num1 is modulus 3 or 5";

Assuming you omitted the first if by mistake, otherwise that’s another error.

Thank you for the nice welcome.

Your solution helped me! However, I am still confused about how the modulus needs to have == 0. I’ve researched it quite a bit and I still cant seem to wrap my mind around it. If you or anyone has time I would welcome any information.

What an elegant, simple straightforward answer. It makes sense to me now. If the remainder of the Var is 0 then if makes the condition true.

I hope I am correct in saying it that way

Thanks again. You guys R O C K!

1 Like