The PHP script is executed on the server and the HTML result is sent to the browser. It can normally have HTML and PHP tags. PHP or Hypertext Preprocessor is a widely used open-source general-purpose scripting language and can be embedded with HTML. PHP files are saved with the .php extension. PHP scripts can be written anywhere in the document within PHP tags along with normal HTML.
$variablename=value;
variable variable$$variablename=value;
function functionname(){
//execution code
}
example:
//define function displayWord
function displayWord($word){
echo $word;
}
//call method
$wordToDisplay=‘Hello World‘ ;
displayWord($wordToDisplay);
if (condition) {
execute code;
}
example:
if ($x>10) {
$y=true;
}
you can use if else in the same way with additional code segment
if (condition) {
execute code;
}
else{
execute another code;
}
for ($from; $condition; $increment) {
execute code;
}
example:
for ($x=0; $x<10; $x=$x+1) {
$y=$x;
echo $y;
}
switch (n) {
case 01:
execute code only if case = 01;
break;
case 02:
execute code only if case = 02;
break;
...
default:
execute code only if none above;
}
example:
$x=100;
switch ($x) {
case 10:
$y=10;
break;
case 20:
$z=20;
break;
...
default:
$a=0;
}