MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology

PHP Programing language

Decision Making in PHP
Previous Home Next

Decision Making

Decision Making Statement is very powerful statement in PHP. It is used in Php to take some decision in PHP Script. It also perform some tasks based on conditinat the time of decision making statements are used.

Types of Decision Making Statement:

The following Decision Making Statements support by PHP

  1. if Statement
  2. if....else Statement
  3. elseif Statement
  4. Switch....Case Statement
if Statement

if Statement is used to execute the statement when only condition is true.

Syntax:
if(condition)
{
Statement1; //if condition is true
}

 

Example:

<html>
<head>
<title>if Statement in PHP</title>
</head>
<body>

<?php
$A=58;
If($A % 2 ==0)
{
echo "$A is Even";
}
?>

</body>
</html>

Output:

if....else Statement

if....else Statement is used to execute the statement when condition is true and execute anorher statement when condition is false.

Syntax:
if(condition)
{
Statement1;  //if condition is true
}
else
{
Statement2;  //if statement1 false
}

Example:

<html>
<head>
<title>if....else Statement in PHP</title>
</head>
<body>

<?php
$A=57;
If($A % 2 ==0)
{
echo "$A is Even";
}
else
{
echo "$A is Odd";
}
?>

</body>
</html>

Output:

elseif Statement

if there are more than one true statemment then there is a use of elseif statement.

Syntax:
if(condition)
{
Statement1;   //code executed when condition is true;
}
elseif(condition)
{
Statemment2;  //code executed when condition is true
}
else
{
Statement3;  //code executed when condition is false
}

Example:

<html>
<head>
<title>elseif Statement in PHP</title>
</head>
<body>

<?php
$A = 39;
echo "Marks is: $A<br/>";
if($A <= 99 && $A >= 70)
{
echo "Result: You got first Position";
}
elseif($A <= 70 && $A >= 55)
{
echo "Result: You got second Position";
}
elseif($A <= 55 && $A >= 40)
{
echo "Result: You got third Position";
}
else
{
echo "Result: Fail";
}
?>

</body>
</html>

Output:

Switch....Case Statement

Switch Statement is used if you want to choose one of many blocks of code to be executed. The switch statement is used to avoid long blocks of if..elseif..else code.

Syntax:
switch (expression)
{
Case 1 :
Sttement1;
break;

Case 2 :
Statement2;
break;
..........
..........
..........
default :
Default Statement;
break;
}

Example:

<html>
<head>
<title>Switch....Case Statement in PHP</title>
</head>
<body>

<?php
$d=date("D");
switch ($d)
{
case "Mon":
  echo "Today is Monday";
  break;
case "Tue":
  echo "Today is Tuesday";
  break;
case "Wed":
  echo "Today is Wednesday";
  break;
case "Thu":
  echo "Today is Thursday";
  break;
case "Fri":
  echo "Today is Friday";
  break;
case "Sat":
  echo "Today is Saturday";
  break;
case "Sun":
  echo "Today is Sunday";
  break;
default:
  echo "Invalid Day.....!!!!!";
}
?>

</body>
</html>

Output:

Previous Home Next