How can we write PHP code?
Let’s start from basic syntax
Basic Syntax
PHP code started with syntax <?php and it ends with syntax ?>
<?php
?>
Hello World Program.
I am going to write a very simple program in PHP, this is just to show how we can write a Hello World program in PHP.
<?php
echo “Hello World”;
?>
We can write it as
<?php
echo ‘Hello World’;
?>
We can also write it as with print keyword.
<?php
print ‘Hello World’;
?>
So we can say to print anything you may use all three above approaches.
The best is to use echo with single quotes
| How can we write php code |
<?php
echo ‘Hello World’;
?>
Math in PHP
How can we add two digits while using PHP?
You can see below code, I added two digits and finally printed result of sum of two digits.Similary we can add multiple digits
<?php
$digit1=5;
$digit2=3;
$sum= $digit1+ $digit2;
echo $sum;
?>
How can we subtract two digits while using PHP?
You can see below code, I subtracted two digit and finally printed result .Similary we can subtract multiple digits
<?php
$digit1=5;
$digit2=3;
$subtract = $digit1- $digit2;
echo $subtract;
?>
How can we multiple two digits while using PHP?
You can see below code, I multipleed two digit and finally printed result .Similary we can do with multiple digits
<?php
$digit1=5;
$digit2=3;
$multiple = $digit1* $digit2;
echo $multiple;
?>
How can we divide two digits while using PHP?
You can see below code, I divided two digit and finally printed result .Similary we can do for divide any digits .
<?php
$digit1=5;
$digit2=3;
$divide = $digit1/ $digit2;
echo $divide;
?>
Math Functions PHP
Function abs()
This function is used to return the absolute value of different numbers
<?php
echo(abs(2.3) . "</br>");
echo(abs(-2.3) . "</br>");
echo(abs(1));
?>
Function acos()
This function is used to return the arc cosine of different numbers
<?php
echo(acos(2.3) . "</br>");
echo(acos(-2.3) . "</br>");
echo(acos(1));
?>

No comments:
Post a Comment