Variable and Constant in PHP:-
Variable:- It is the special identifier in PHP whose value can be changed. variable always will be declared using alphabets.
PHP variable will be started from $ symbol.
Syntax of Variable Declaration in PHP
$identifier=value
$a=10; //Integer Type Variable
$b="10"; //Numeric String
$c = '10'; //Numeric String
$d = 10.0; //Float Value
PHP provides a loosely coupled declaration for variable means no need to write data type on the variable declaration, it will be managed by assigned data.
using this concept we can use a single name variable for multiple values.
$a=10;
$a = "abc";
$a =True;
mobile no = "9812311111" //incorrect
Variable:- It is the special identifier in PHP whose value can be changed. variable always will be declared using alphabets.
PHP variable will be started from $ symbol.
Syntax of Variable Declaration in PHP
$identifier=value
$a=10; //Integer Type Variable
$b="10"; //Numeric String
$c = '10'; //Numeric String
$d = 10.0; //Float Value
PHP provides a loosely coupled declaration for variable means no need to write data type on the variable declaration, it will be managed by assigned data.
using this concept we can use a single name variable for multiple values.
$a=10;
$a = "abc";
$a =True;
mobile no = "9812311111" //incorrect
mobile_no= "981233444" //correct
1a = 10 // incorrect
a1=10 //correct
note:- space,numeric,keyword,capital letter,special char not allowed in variable declaration.
WAP to calculate Simple Interest in PHP?
<?php
echo "<h1>SI Program</h1>";
echo "<hr>";
$p=12000;
$r=2.2;
$t=2;
$si = ($p*$r*$t)/100;
echo "p=$p,r=$r,t=$t,result=$si ";
//echo $p,$r,$t,$si;
?>
Constant in PHP:-
we can not change the value of the identifier in the program using constant.
in PHP constant will be defined by define() and access by without $ symbol.
Syntax of Constant in PHP:-
define('identifier',value)
define(a,100)
define(b,200)
define(a,20) //error because we can not change value of constant
echo a;
echo b;
Example of Constant in PHP?
<?php
define('a',100);
define('b',200);
#define('a',10);
echo a+b;
?>
WAP to swap two number with using the third variable:-
<?php
$a=10;
$b=20;
echo $a,$b,"<br>";
$temp=$a;
$a=$b;
$b=$temp;
echo $a,$b;
?>
Variable and Constant in PHP
Assignment of PHP:-1) WAP to Swap Two Number Without Using Third Variable?
<?php
$a=100;
$b=20;
echo $a,", ",$b,"<br>";
$a=$a+$b; //120
$b=$a-$b; //100
$a=$a-$b; //20
echo $a," ," ,$b;
?>
2) WAP to Calculate Square and Cube of any number?
<?php
$num=5;
$sq = $num*$num;
$cb = $num*$num*$num;
echo "Square is ",$sq;
echo "Cube is ",$cb;
?>
3) WAP to Calculate Area of Circle?
4) WAP to Calculate Area of Triangle?
5) WAP to convert temperature from Celsius to Fahrenheit?
shadab shah
ReplyDelete$a=8;
$b=14;
echo $a,",",$b,"
";
$a=$b+$a;
$b=$a-$b;
$a=$a-$b;
echo $a,",",$b;
Aamir Uddin
ReplyDelete$a=16;
$b=4;
echo $a,",",$b,"
";
$a=$a+$b; //20
$b=$a-$b; //16
$a=$a-$b; //4
echo $a,",",$b;
Aamir Shaikh
ReplyDeleteHow to calculate area of tringle
<?php
$base=21;
$height=23;
echo "area with base $base and height $height=". ($base*$height)/2;
?>
Shadab Shah
ReplyDeleteHow to Convert Celsius to Fahrenheit
Aamir Shaikh
ReplyDeleteHow to Calculate the area of Circle
Mansi Dubey
ReplyDelete<?php
$r=5;
$area_of_circle=(3.14*$r*$r);
echo "Area of circle is = ".$area_of_circle;
?>
Mansi Dubey
ReplyDelete<?php
$r=5;
$area_of_circle=(3.14*$r*$r);
echo "Area of circle is = ".$area_of_circle;
?>
Mansi Dubey
ReplyDelete<?php
$r=5;
$area_of_circle=(3.14*$r*$r);
echo "Area of circle is = ".$area_of_circle;
?>
Mansi Dubey
ReplyDelete<?php
$base=100;
$height=50;
$area_of_triangle=(1/2*$base*$height);
echo "Area of triangle is = ".$area_of_triangle;
?>
Mansi Dubey
ReplyDelete<?php
$C=32;
$F=$C*1.8+32;
echo "Temperature in Fahrenheit = ".$F;
?>
Kritika Barod
ReplyDeleteCalculate Area of Circle--
Area of Circle is A=$A";
?>
Kritika Barod
ReplyDeleteconvert temperature from Celsius to Fahrenheit
";
$f=($t*9/5)+32;
echo "F is=$f";
?>
";
ReplyDeleteecho "area of circle is - $A";
?>
Calculate Area of Triangle
ReplyDelete$b=10;
$h=12;
$at = ($b*$h)/1/2;
echo "Area of Triangle is ".$at;
echo ("
") ;
echo ("
") ;
echo"The Formula of Area of Triangle is =(b*h)/1/2";
Area of Circle
ReplyDeletedefine('a',3.142);
$num=5;
$sq=$num*$num;
$a= a*$sq;
echo ("
");
echo "Area of Circle is " .$a;
Celsius To Fahrenheit Converter
ReplyDelete$c=6;
$f=(($c*9)/5)+32;
echo "Celcius to Fahrenheit Converter";
echo ("
");
echo ("
");
echo ("
");
echo "$c Degree Celcius Temperature is Equal To ". $f , "", ' Fahrenheit';
//area of rectangle
ReplyDelete$l=10;
$b=20;
$area=$l*$b;
echo("Area of rectangle is:-" .$area);
// area of triangle
ReplyDelete$base=20;
$height=10;
$t_area=($base*$height)/2;
echo("
");
echo("Area of triangle:-" .$t_area);
// area of circle
ReplyDelete$r=5;
define('pi',3.14);
$c_area=pi*$r*$r;
echo("
");
echo("Area of circle:-" .$c_area);
// program to convert temperature from Celsius to Fahrenheit fahrenheit = (celsius * 1.8) + 32
ReplyDelete$c=37;
$f=$c*1.8+32;
echo("
");
echo("Temperature in celsius:-" .$f);
","
ReplyDelete";
echo "$cube";
?>
WAP to find greater number using if else condition
ReplyDelete$b)
{
echo "a is greater";
}
else
{
echo "b is greater";
}
?>