Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

PHP Practicals

Php program in mca

Uploaded by

rocky70308
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

PHP Practicals

Php program in mca

Uploaded by

rocky70308
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

php practicals

practical 2: simple calci

Code:
<?php
echo " practical 2 simple calci";
$a=10;
$b=5;
$c=$a+$b;
echo "THE ADDITION OF $a AND $b IS : $c \n";
$c=$a-$b;
echo "THE SUBSTRACTION OF $a AND $b IS : $c \n";
$c=$a*$b;
echo "THE MULTIPLICATION OF $a AND $b IS : $c \n";
$c=$a/$b;
echo "THE DIVISION OF $a AND $b IS : $c \n";

?>
OUTPUT:
PRACTICAL NO 3 :IF ELSE CONDITION
CODE:
<?php
echo " practical 3 : IF ELSE CONDITION \n";
$t= date("H");
if($t < "12"){
echo "GOOD MORNING !!!";
}
elseif($t < "16"){
echo"GOOD AFTERNOON";
}
elseif ($t < "19"){
echo"GOOD EVENING";
}
else{
echo"GOOD NIGHT~~";
}
?>
OUTPUT:
PRACTICAL NO. 4

CODE:
<?php
echo " practical 4 : FOR LOOP\n";
echo"EVEN NUMBERS ARE \n";
for($i=0;$i<=100;$i+=2)
{
echo $i."\t";
}
echo"\n ODD NUMBERS ARE \n";
for($i=1;$i<=50;$i+=2)
{
echo $i."\t";
}
OUTPUT:

PRACT 5
CODE:
<?php
echo " practical 5 : while LOOP\n";
$i=0;
while($i<=10)
{
echo"THE NUMBER IS : " . $i ."\n";
$i++;
}
?>

OUTPUT:

PRACT 6
CODE:
<?php
echo " practical 5 : DO....while LOOP\n";
$i=0;
do
{
echo "THE NUMBER IS :". $i . "\n";
$i++ ;
}
while($i<=10);

?>
OUTPUT:
PRACT 8
CODE:
<?php
echo " practical 8 : FOREACH LOOP\n";
echo"OUTPUTOF AN ARRAY";
$person=array("VMV","JMT","JJP","COLLEGE");
foreach($person as $value)
{
echo $value. "\n";
}
echo"\n";
# assocative array
echo "OUTPUT OF ASSOCATIVE ARRAY \n";
$color=array("r"=>"red", "g"=>"green", "b"=>"blue", "w"=>"white");
foreach($color as $key=>$val)
{
echo $key."-->".$val."\n";
}
?>
OUTPUT:
PRACTICAL NO :09
CODE:

<?php
#ceil() Rounds a number up
$num=20.7;
echo"\n ceil of $num is:". ceil($num);
#floor() round the number down
echo"\n cfloor of $num is:". floor($num);
#abs() Finds the absolute value of number
echo"\n abs of -20 is:". abs(-20);
#pow() RAISE one number to the poer of anaother
echo"\n cube of 4 is:". pow(4,3);
#exp() finds the exponent of a number
echo"\n Exponent of 1 is:".exp(1);
#rand() Genertes a random number
echo"\n RANDOM FROM 10 to 99 is:". rand(10,99);
#bindec() converts a number from binary to decimal
echo"\n decimal of 1000 is:".bindec(1000);
#decbin() converts a number from decimal to binary
echo"\n binary of 7 is:".decbin(7);
#decoct() converts a number from decimal to octale
echo"\n Octal of 59 is:".decoct(59);
#octdec() converts a number from octal to decimal
echo"\n decimal of 47 is:".octdec(47);
#dechex() converts a number from decimal to hexadecimal
echo"\n decimal of 2073 is:".dechex(2073);
#hexdec() converts a number from hexadecimal to decimal
echo"\n decimal of DAD is:".hexdec(DAD);
#round find round number
echo"\n round of $num is:".round($num);
#sqrt
echo"\n sqrt of 25 is:".sqrt(25);
?>

OUTPUT:

PRACT 10 star pattern


CODE:
<?php
$a=10;
for($i=1;$i<$a;$i++)
{

for($j=1;$j<$a-$i;$j++)
{

}
for($z=1;$z<=$i;$z++)
{
echo" *";
}
for($k=1;$k<=$i;$k++)
{
}
echo"\n";
}

OUTPUT:

PRACT 11 var_dump()
CODE:
<?php
$num=100;
$fnum=15.186;
$str="vmv";
$bol="false";
var_dump($num);
var_dump($num,$fnum,$str,$bol);
?>

OUTPUT:
PRACT 12 is_int()
CODE:
<?php
$a=300;
$b=99.9;
if(is_int($a) and is_int($b))
{
$sum=$a+$b;
echo $sum;
}
else
{
echo"Both number should be integer";
}
?>
OUTPUT:

PRACT 13 switch case


CODE:
<?php
$day=7;
switch($day)
{
case 1:
echo"MONDAY";
break;
case 2:
echo"TUESDAY";
break;
case 3:
echo"WEDNESDAY";
break;
case 4:
echo"THRUSDAY";
break;
case 5:
echo"FRIDAY";
break;
case 6:
echo"SATURDAY";
break;
Default:
echo"IT'S SUNDAY";
}
?>

OUTPUT:
PRACT 14 OPERATOR PRECENDENCE
CODE:
<?php
# operator precendence
echo"output of operator precendence using paranthesis \n";
echo(((4*5)-2)/10);
echo"\noutput without paranthesis";
echo 4*5-2/10
?>

OUTPUT:

You might also like