0

In this episode We discussion about if....else statement .


But first we discussion about Multiple if statement.
When you write php code you want to perform some action for some condition.

Like

  • if(expression) { //your statement. }
  • if(expression){ //your statement }
  • if(expression){ //your statement. }



Now we discussion about grading system ; Where we use just one Mark for our grading.

Run code online click here

In php tutorial Conditional statement is Important for logic. If ....else is another php conditional operator .When working with the if statement , You will often want to define an alternative block of code that should be executed if the expression you are testing evaluates of false. You can do this by adding else to the if statement followed by a further block of code. like so:
if(expression)
{ //code to execute if the expression evaluates to true }
else { //code to execute in all other case }

The php else statement is execute when the php if expression evaluate to false . Now we small program practices:

In this program php if condition is false so it execute the else statement.
Out put is: Another thing.

You can Run this code in online php editor

You can Run this code in online php editor

Out put is:Both the number and the letter matched .
Because php if condition is true.So it print this (Both the number and the letter matched )
You can change the value of the variable and look the change of condition.

In this program we Use the php date()function. You change the value of $d ,In the condition of php if Like
$d=date("D");
if($d=="Mon or Fri or Sun")
And look the change.

You can Run this code in online php editor

Out put is :You are not allowed to drink alcohol



In this if..else statement out put shown You are not allowed to drink alcohol
because our variable value is 20. But condition is $age >= 21,
variable age says that greater than or equal to 21 so condition is false

This is another php if...else program.

So keep practicing . And stay with us for next php conditional (if...elseif...else) tutorial .
Hope you enjoy it.

Post a Comment

 
check pagerank
Top