Searching...
22 Nisan 2013 Pazartesi

PHP Second Tutorial - IF Clause and Variables


First Tutorial ...


Beginning...


Second PHP article.

Article's Objectives:
  • Learn variables
  • Learn IF,ELSE and ELSEIF
  • Make little '18+ Age Control' example

Variables

Variables, like a box. You can make any value in box. For example (toys,ball,name vs).
<?php
$thisisvariable = "This is variable";
?>
You can use variables IN ANY PHP FUNCTION.
<?php
$name = "Eray";
echo "My name is ".$name;
?>

IF Clause

IF

First if clause tag is 'IF'. IF you want check some variables you can use 'IF'. For example;
<?php
if(1 == 2)
{
echo "Math is broken!";
}
?>

ELSE

ELSE is IF's reverse. Other name is IFNOT
<?php
if(1 == 2)
{
echo "Math is broken!";
}
else
{
echo "Absolute, wrong!";
}
?>

ELSEIF

 Elseif is mean ' ELSE AND IF '.You can write else after if but ELSEIF small and lite.
<?php
$user= "Man";
if($user== "Man")
{
echo("Hello Mr.");
}
elseif($user == "Woman")
{
echo("Hello Mrs.");
}
else
{
echo("Hello!");
}
?>

Age Control System

In age control system, we use IF,ELSE,ELSEIF and VARIABLES.

We must start PHP tag
<?php
After we set a age variable
$age = 18;
When we set age, we check if age bigger then 18
if($age > 18)
{
echo("You can use site");
}
We check if age equals 18
<?php
elseif($age == 18)
{
echo("You must age 1 more year");
}
?>
End we check if age smaller then 18(if is not 18 and >18)
<?php
else
{
echo("You must wait too long...");
}
?>

Homework ( Ohh No! ) 

  1. Make small login panel (username : phpfast | password : fastphp) (Not login form only variables)

0 yorum:

Yorum Gönder