php workshop l02 php basics
Post on 15-Jul-2015
162 Views
Preview:
TRANSCRIPT
Web Basics Programming With PHP
Web Programming Languages
Before we start
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
http://www.aptana.com/products/studio3/download
Wampserverhttp://www.wampserver.com/en/
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
Lesson 1 Overview:
Control statements
Functions
Loops
Arrays4
3
2
1
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
Control Statements
•Ifif (condition)
{
code to be executed if condition is true;
}
•Example
$Successful=true;
if ($Successful==true)
{
echo "Have a good day!";
}
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
Control Statements
•If elseif (condition)
{ code to be executed if condition is true;}
else
{ code to be executed if condition is false; }
•Example
$Successful=true;
if ($Successful===true)
{echo "Have a good day!"; }
else
{ echo "Have a work day!"; }
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
Loops
•Whilewhile (condition is true)
{
code to be executed;
}
•Example$x=1;
while($x<=5) {
echo "The number is: $x <br>";
$x++; }
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
Loops
•Forfor (init counter; test counter; increment counter)
{
code to be executed;
}
•Examplefor ($x=0; $x<=10; $x++)
{
echo ‘<p align=“center”The number is: ‘.$x.’
<br>’;
}
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
Loops
•Foreachforeach ($array as $value)
{
code to be executed;
}
•Example$colors = array("red","green","blue","yellow");
foreach ($colors as $value)
{
echo "$value <br>";
}
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
Function
•Function
function functionName()
{
code to be executed;
}
•Example
function writeMsg()
{
echo "Hello world!";
}
writeMsg();
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
Function
•Function Arguments
function writeMsg($Msg)
{
echo $Msg;
}
•Example
writeMsg("Hello world! ");
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
Arrays
•Arrays
$fruits=array(
"apple", "banana“
);
$fruits[2]="orange";
•Example
$fruits[0] is "apple"
$fruits[1] is "banana"
$fruits[2] is "orange"
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
Arrays
•Arrays$age=array(
"mohammad"=>"22","opada"=>"25"
,"ahmad"=>"43“
);
•Example
$age["mohammad"] is "22"
$age["opada"] is "22"
$age["ahmad"] is "43"
THANK YOU!
top related