PHP if -- else statement in conditions

If statement enable programmer to execute a script only when a condition is true.
And Else enable to quickly execute a script when the condition fails.

PHP Code:
<?php
$myname = "Smith" ;
if ( $myname == "Smith" ) {
echo "hello ! Your are Smith"; // wil be displayed only if condition is true
} else
{
echo "hello ! Your are not Smith";
// wil be displayed only if condition is false
}
?>
This may also be writed like this:
<?php
$myname = "Smith" ;
if ( $myname == "Smith" )
echo "hello ! Your are Smith"; // wil be displayed only if condition is true
else

echo "hello ! Your are not Smith";
// wil be displayed only if condition is false
?>
"{" and "}" can be deleted because there is only one line in if and else statements. If you want to create many lines of script, so then you should use"{" and "}":

PHP Code:
<?php
$myname = "Smith" ;
if ( $myname == "Smith" )
{
echo "hello ! Your are Smith"; // wil be displayed only if condition is true
echo "You are wellcome";
} else

echo "hello ! Your are not Smith";
// wil be displayed only if condition is false
?>
Here the "{" and "}" are necessary in the if statement, but not necessary in the else one as else statement has only one line of code.

PHP simple if statement

if statement in php is similar to almost all languages, and it necessary to make a usefull script.

If statement enable you to execute a script only if a condition is true.

Simple if statement:

php code:
<?php
$age = 28;

if ($age == 28)
echo "hello ! Your age is 28";
?>
Display:
hello ! Your age is 28

But if you want to do many lines of code under the if statement, you should do:

php code:
<?php
$age = 28;

if ($age == 28)
{
echo "hello ! Your age is 28";
echo "
" ;

echo "You are wellcome !";

?>
Display:
hello ! Your age is 28
You are wellcome !

PHP strpos a searching function

strpos() is a very usefull php function that will find a string into another string.

This function takes two parameters: the string your are searching in and the string you are searching for, and it returns the position of the first match, or false if not found.

PHP Code:
$mystring = "May 16, 1990" ;
$search = "19" ;
$pos = strpos(
$mystring , $search ) ;
echo $pos ;
Display:
8
Note:
PHP Start from 0, so the first position is position 0 , the second is 1 ...

The searched string may also be a character, or a number that will be considered as an ASCII code of the searched character.