PHP if else statement- Normal and advanced

Here now I am giving you the normal code example.

$test = 100;

if ( $test == 100 ) {
echo “The if statement evaluated to true”;
} else {
echo “The if statement evaluated to false”;
}

If you want to use this in one line than use following code:

echo $testprint = ( $test == 100 ) ?  “The if statement evaluated to true” : “The if statement evaluated to false”;

This will gives you same output.

Now I am giving you the multiple IF else statment in very short way.

if ( one= true ){
if ( two=true){
echo “one”;
}else{
echo “two”;
}
}else{
echo “nothing”;
}

Short way:

$shortway = (one= true) ? (two=true ) ? “one” : ‘two’ ) : “nothing”;

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.