Here are some basic programs using PHP
1. Arithmetic operation program using PHP
<?php $str=" Arithmetic operation"; $a=4; $b=5; $c=$a+$b; echo "Sum=", $c; $c=$a-$b; echo "<br>Sub=", $c; $c=$a*$b; echo "<br>Mul=", $c; $c=$a/$b; echo "<br>Div=", $c; ?>
2. PHP program to print person name and age.
<?php $name="John"; $age=20; echo "Person name=", $name; echo "<br>Age=", $age; ?>
3. PHP Program to SWAP 2 Numbers
<?php $a=4; $b=5; echo "A: before swap=", $a; echo "<br>B: before swap=", $b; $c=$a; $a=$b; $b=$c; echo "<br>A: After swap=", $a; echo "<br>B: After swap=", $b; ?>
4. PHP Program to test whether the number is +ve or -ve.
<?php
$a=-10;
if ($a>0)
{
echo "Number is positive";
}
else
{
echo "Number is negative";
}
?>
5. PHP program to test whether the person is Eligible to vote or not.
<?php
$age=19;
$name="John";
if ($age>=18)
{
echo $name, " is eligible for vote";
}
else
{
echo $name, " is NOT eligible for vote";
}
?>
