Wednesday 3 January 2018

Basic PHP Programs



Display "Welcome To LearningPoint92"
<?php
echo " Welcome To LearningPoint92 ";
?>

Output:

Welcome To LearningPoint92 

Addition of two Numbers

<?php

 $a=50;
$b=100;

$c=$a+$b;

echo "Sum = $c</br>";
?>

Output:

Sum = 150

Note: Php variables are declared by $(sign) and there is no need to declare datatype before variable name.
Example:$a,$b,$name

Print Student Details

<?php

$name="Rushi";
$age=22;
$mark=80.35;

echo "Student Details</br>";
echo "Name:$name</br>";
echo "Age:$age</br>";
echo "Mark:$mark</br>";
?>

Output:

Student Details
Name:Rushi
Age:22
Mark:80.35

Swapping of two numbers

<?php

$x=50;
$y=40;

echo "Value of x before swapping:$x</br>";
echo "Value of y before swapping:$y</br>";

$temp=$x;
$x=$y;
$y=$temp;

echo "Value of x after swapping: $x</br>";
echo "Value of y after swapping: $y</br>";

?>
Output:

Value of x before swapping:50
Value of y before swapping:40
Value of x after swapping: 40
Value of y after swapping: 50

Swapping of two numbers without using third variable

<?php

$x=50;
$y=40;

echo "Value of x before swapping:$x</br>";
echo "Value of y before swapping:$y</br>";

$x=$x+$y;
$y=$x-$y;
$x=$x-$y;

echo "Value of x after swapping: $x</br>";
echo "Value of y after swapping: $y</br>";

?>
Output:
Value of x before swapping:50
Value of y before swapping:40
Value of x after swapping: 40
Value of y after swapping: 50

Calculate Area of triangle

<?php

$b=5;
$h=9;

$result=0.5*$b*$h;

echo "Area of triangle is:$result</br>";

?>
Output:
Area of triangle is:22.5

Calculate total and average marks of 3 subjects

<?php
$m1=50;
$m2=22;
$m3=80;
$sum=$m1+$m2+$m3;
$avg=$sum/3;
 echo "Total:$sum</br>";
echo "Avg:$avg</br>";
?>
Output:
Total:152
Avg:50.666666666667

Calculate Simple Interest

<?php

$p=5000;
$t=2;
$r=10;

$si=$p*$t*$r/100;

echo "Simple interest:$si</br>";

?>
Output:
Simple interest:1000

Calculate Area of Circle

<?php

$r=10;

$Area=3.14*$r*$r;

echo "Area of circle is:$Area</br>";

?>
Output:
Area of circle is:314

Calculate Area of Square and Area of Rectangle

<?php

$side=10;
$length=30;
$Width=20;

$AreaOfSquare=$side*$side;
$AreaOfRectangle=$Width*$length;

echo "Area of Square is:$AreaOfSquare</br>";
echo "Area of Rectangle is:$AreaOfRectangle</br>";

?>

Output:
Area of Square is:100
Area of Rectangle is:600

Calculate all arithmetic operation(+,-,*,%,/)

<?php

  $a=50;
  $b=10;
$sum=$a+$b;
$sub=$a-$b;
$mul=$a*$b;
$quo=$a/$b;
$rem=$a%$b;

echo "Addition is $sum</br>";
echo "Subtraction is $sub</br>";
echo "Multiplication is $mul</br>";
echo "Quotient is $quo</br>";
echo "Reminder is $rem</br>";

?>

Output:

Addition is 60
Subtraction is 40
Multiplication is 500
Quotient is 5
Reminder is 0

No comments:

Post a Comment

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...