PHP conditions
Last update on: 09-24-2008Maybe you have already seen a script and you've noticed things like,
if( $var == 'ok') { print 'test'; } else{ print 'refuse'; }
if($var == 'ok') //if the variable named $var is equal to ok { print 'test'; //so we display the result } else{ // else we display another message print 'refuse'; }
Example 1: with if else elseif.
$variable = 'car'; if($variable == 'car'){ print 'good! you found it'; } elseif($variable =='bike'){ print 'you are so close!'; } else { print 'it\'s not the answer, try again'; }
Example 2: switch().
switch($operation) { case '1': // If the variable equal to 1 print ' operation number 1'; // display this phrase break; // we close this case case '2':// If the variable equal to 2 print 'operation number 2'; break; default: // If the variable doesn't have any value print 'operation by default'; // Display something by default }
The control operators:
|
==
|
strictly equal
|
|
!=
|
different
|
|
>
|
more than
|
|
<
|
less than
|
|
>=
|
more or equal to
|
|
<=
|
less or equal to
|
|
&&
|
and
|
|
||
|
or
|
|
AND
|
and
|
|
OR
|
or
|
|
TRUE
|
1 or yes
|
|
FALSE
|
0 or false
|
The mathematical operators:
|
+
|
addition
|
|
-
|
subtraction
|
|
/
|
division
|
|
*
|
multiplication
|
|
%
|
modulo
|
To your keyboards and start typing and testing.
PHP and MySQL's lessons:
Introduction To PHPGet Started With PHP
PHP Variables
PHP Variables Of Environment
PHP Conditions
PHP Looping
PHP Cookies
PHP Working With Dates
PHP Working With Arrays
PHP Working With Files
PHP Play With Strings
PHP And Forms
Send Emails With PHP
The Include Statement
Get Started With MySQL
MySQL Update And Delete
The WHERE Clause
MySQL Functions
Guestbook Script
Websites Directory Script
Multiple Pages With PHP
Create Your Forum With Php

