Conditional Statements

Conditional Statements

Is used to execute a user (or a block of instructions), but only under certain circumstances – predetermining condition is met (or the whole set of conditions).

Example

<? php
if (conditional_expression)
instruction executed if the condition is met
elseif (other_conditional_expression)
instruction executed if the second condition is met, and the first not
else
instruction executed if not met none of the conditions
?>

A conditional statement is any expression, because the condition is recognized all returns or all of the variables, boolean expressions, etc. With the condition is regarded as a value greater than zero.

Example

<? php

$ a = 2;
$ b = 6;
$ c = 4;

if ($ a> $ b)
echo „$ a is greater than $ b ‚;
elseif ($ b> $ c)
echo „$ b is greater than $ c”;
else
echo „$ c is greater than $ a and $ b”;

if ($ a)
echo „$ a variable has a value greater than zero”;

?>

 

Example

<? php

$a = 8;
$b = 7;
$c = 1;

if ($a> $b) {

echo „$a is greater than $b „;

if ($a> $c)
echo „and the $c”;             // You should see the message „8 is greater than 7, and 1”

}

?>

Cookies help us deliver our services. By using our services, you agree to our use of cookies. More Info | Close