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”;

Rails if else statement

Here i am going to give some example of conditional statements in Rails.
Normal IF ELSE
<% if user %>
<%= user.name %>
<% else %>
Anonymous
<% end %>

Normal code for ELSIF
if var == 10
print “Variable is 10″
elsif var == “20″
print “Variable is 20″
else
print “Variable is something else”
end

Technic:
How to Put this in one line:
<%= user.name if user %> This is the simplest way.

How to use IF and ELSE statement in one line:
<%= user ? user.name : “Anonymous” %>