- Language for developing Dynamic web applications
- PHP scripts run on the server
- A PHP program may contain HTML,CSS and JS along with it
- “.php” is the file name extension
$name = "Rick";
$money = 10.5;
$boolean = true;
$age = 30;
A letter must start with underscore or a letter.
Variables names are case sensitive.
echo "My name is ". $name . "My age is $age";
echo " I have $money in my pocket.";
- Global Variables
- Local Variables
- Static Varibles
- String
- Integer
- Float
- Integer
- Boolean
- Array
- Object
$colleges = array("NIST","Kathmandu University","St.Xaviers");
var_dump($colleges);
echo $colleges[0];
echo $colleges[1];
Associative Arrays:
$bio = array("jack" => "12","crow" => "14","zen" => "18");
foreach($bio as $name => $age) {
echo $name . "=" . $age;
echo "<br>";
}
if (condition) {
// code to be executed
} elseif {
// code to be executed
} else {
// code to be executed
}
$x = 0;
while ( $x <= 25) {
echo "The number is: $x";
$x++;
}
for (i = 0; i < 10; i++) {
echo "number: $i";
}
function function_name(parameters) {
// code to be executed;
}
function_name(parameters);