Jump to content

[SOLVED] newbie PHP Question


chaddsuk

Recommended Posts

Hi im having issues figureing out how the if statement works correctly

 

im using the following...

 

 

<?php

    $var = 5;

    if ($var == 5)

   

(

        echo "var was true<br>";

)

 

        ?>

 

ive found that if i remove the curly braces around my echo it works, but if i do that i cant insert code independent of the IF statment?

 

Im using PHP5 btw

 

any help would be appreciated

 

cheers

 

chris

 

 

Link to comment
https://forums.phpfreaks.com/topic/85204-solved-newbie-php-question/
Share on other sites

$var = 5;
     if ($var == 5) 
{
        echo "var was true";
}

 

use curly braces - you use () for the statement you are testing and {} for the code you want done

 

I'm not sure what you mean by "independent of the if statement" ?

 

you can add all the code you want that's not within the IF statement:

 

$var = 5; //this is independent of the if statement
     if ($var == 5) 
{
        echo "var was true";
}
//any code here will be independent of the IF statement

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.