Sahilphpoutput
Sahilphpoutput
<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
$students = array(
array("sahil", "dawange", 19),
array("prajwal", "ahire", 19),
array("snehal", "koli", 19)
);
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:-