Chapter 2 p2
Chapter 2 p2
1 11/17/2023
Chapter 2 Advanced Internet Programming
Decision making statement
The if, else if ...else and switch statements are used to
take decision based on the different condition.
You can use conditional statements in your code to
make your decisions.
PHP supports following three decision making
statements:
if...else statement - use this statement if you want to
execute a set of code when a condition is true and
another if the condition is not true
<html><body>
<?php $a = 0; $b = 0;
for( $i=0; $i<5; $i++ )
{
$a += 10;
$b += 5;
}
echo ("At the end of the loop a=$a and b=$b" );
?>
</body>
</html>
<html> <body>
<?php $array = array( 1, 2, 3, 4, 5);
foreach( $array as $value )
{ if( $value == 3 )continue;
echo "Value is $value <br />"; } ?>
</body></html>