0% found this document useful (0 votes)
12 views15 pages

Snehalphpoutput

The document contains multiple PHP practical examples demonstrating basic programming concepts such as decision-making statements (if-else, switch), looping statements (for, foreach, do-while, while), and array manipulations (indexed, associative, multidimensional). It also covers string manipulation functions and a simple class structure with inheritance. Each practical example includes PHP code snippets and their expected outputs.

Uploaded by

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

Snehalphpoutput

The document contains multiple PHP practical examples demonstrating basic programming concepts such as decision-making statements (if-else, switch), looping statements (for, foreach, do-while, while), and array manipulations (indexed, associative, multidimensional). It also covers string manipulation functions and a simple class structure with inheritance. Each practical example includes PHP code snippets and their expected outputs.

Uploaded by

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

Practical1

<html>
<body>
<?php
echo"WelcometoPHP!!";
?>
</body>
</html>

Output:
Practical 2
DecisionMakingStatements
If- Else

<?php
$num=23;
if($num%2==0)
{
echo"Numberis Even.";
}
else
{
echo"Numberis Odd.";
}
?>

Output:
Switch
<html>
<body>
<?php
$ch=2;
$a=10;
$b=45;
switch($ch)
{
case 1:
echo("Addition:".($a+$b));
break;
case 2:
echo("Substraction:".($a-$b));
break;} ?>
</body>
</html>
Output:
Practical 3
LoopingStatements
 ForLoop
<?php
$i=10;
for($i=1;$i<=10;$i++)
{
echo $i."<br>";
}
?>
Output:
 ForEach

<?php
$arr=array('a','b','c');
echo"ArrayElementsAre:<br>";
foreach($arr as $value)
{
echo($value)."<br>";
}
?>
Output:
DoWhileLoop:
<?php
$n=5;
$i=1;
echo"Tableof5:<br>"; do
{
echo($n)."*".($i)."=".($n*$i)."<br>";
$i++;
}while($i<=10);
?>
Output:
While Loop:
<?php
$n=9;
$i=1;
echo"Tableof9:<br>";
while($i<=10)
{
echo($n)."*".($i)."=".($n*$i)."<br>";
$i++;
}
?>
Output:
Practical 4
IndexedArray:
<?php
$arr=array(58,52,89);
echo"ThearrayElementsare:<br>".$arr[0].",".$arr[1].",".$arr[2];
?>

Output:
AssociativeArray:
<html>
<body>
<?php
$capital=array("India"=>"NewDelhi","USA"=>"WashingtonDC","France"=>"Paris");
print_r($capital);
echo"<br>";
?>
</body>
</html>
Output:
MultiDimensionalArray:
<?php
$student=array(
array("Vaibhav","Rathore",19),
array("Krishna","Rathore",19),
array("Kunal","Sanap",19),
);
foreach($studentas$student)
{
echo$student[0]."".$student[1]."is".$student[2]."years old.<br>";
}
?>
Output:
Practical 5
(ManipulatingstringFunctions)
• Lengthof String
<?php
$str="WelcometotheworldofPHP";
$length=strlen($str);
echo"<br>Length ofstring : ".$length;
?>

Output:
 No.ofWordsinString
<?php
$str="Hello world";
$count=0;
for($i=0;$i<=strlen($str);$i++)
{
if($str[$i]==""||$str[$i]==null)
{
$count=$count+1;
}
}
echo"No.ofWordsinString=".$count;
?>
Output:
 AllString Functions
<?php
$string="StringHASit'sPredifinedFUNctions:";
$str="Stringhasitsown functions:";
echo"Thelengthofthestringis:".strlen($str); echo
"<br>";
echo"TheResultofcomparingstringis:".strcmp($string,$str); echo
"<br>";
echo"TheResultoftheRepeatedstringis:".str_repeat($str,3); echo
"<br>";
echo"TheReplacedstringis:".str_replace("Predifined","Builtin",$string); echo
"<br>";
echo"TheResultofUpperCaseis:".strtoupper($string);
echo "<br>";
echo"TheResultofLowerCasestringis:".strtolower($str); echo
"<br>";
echo"TheResultofLtrimstringis:".Ltrim($string); echo
"<br>";
echo"TheResultofRtrimstringis:".Rtrim($string); echo
"<br>";
echo"TheResultofWordCountis:".str_word_count($str); echo
"<br>";
echo"TheResultofPossitionis:".strpos($string,"it's"); echo
"<br>";
echo"TheResultofPossitionis:".ucwords($str);
echo "<br>";
echo"TheResultofReverseis:".Strrev($str); echo
"<br>";
?>
Output:
PracticalNo.08
Code:-
<?php
classFruit
{
public$name;
public$color;
public function construct($name,$color)
{
$this->name=$name;
$this->color=$color;
}
publicfunctionintro()
{
echo"theFruitis{$this->name}andthecoloris{$this->color}";
}
}
classMangoExtendsFruit
{
publicfunctionMessage()
{
echo"TheFruitnameandcolorisyellowornot?<br>";
}
}
$Mango=newMango("Mango","yellow.");
$Mango->Message();
$Mango->intro();
?>
Output:-

You might also like