Program Code3php
Program Code3php
<?php
$Str = "A VanishPokharkar";
echo strlen($Str);
?>
<html>
<head>
<title> Count the number of word in string </title>
</head>
<body>
<?php
$string = "hello, world! this is a sample string";
$word=1;
for ($i =0; $i < strlen($string); $i++)
{
if ($string[$i] == ' ')
{
$word++;
}
}
echo "The number of words in the string is:".$word. "\n";
?>
</body>
</html>
Exercise:
Write a program to demonstrate PHP maths function.
<?php
$n1=100;
$n2=5;
$n3=min($n1,$n2);
echo "Min is : $n3"."<br><br>";
$n1=max($n1,$n3);
echo "Max is : $n1"."<br><br>";
$n4=sqrt($n1);
echo "sqrt is : $n4"."<br><br>";
$n1=pow($n2,$n4);
echo "pow is : $n1"."<br><br>";
echo "ceil : ".ceil($n1)."<br><br>";
echo "floor : ".floor($n2)."<br><br>";
echo "round : ".round($n3.$n1)."<br><br>";
echo "abs : ".abs($n4);
?>
Program Code:
Write a program to demonstrate anonymous function.
<?php
$arr = [10,3,70,21,54];
usort ($arr, function ($x , $y) {
return $x > $y;
});
foreach ($arr as $x){
echo $x . "<br>";
}
?>
Exercise:
Write a Program to demonstrate parameterized function.
<?php
function addfunc($num1,$num2)
{
$num=$num1+$num2;
echo "sum of the two numbers is:".$num;
}
addfunc(50,20);
?>
Program Code:
1.Write a program to implement multilevel inheritance.
<?php
class grandparent
{
function dis1()
{
echo "Grand-Parent";
echo "<br>";
}
}
class parents extends grandparent
{
function dis2()
{
echo "Parents";
echo "<br>";
}
}
class child extends parents
{
function dis3()
{
echo "Child";
echo "<br>";
}
}
$obj=new child();
$obj->dis1();
$obj->dis2();
$obj->dis3();
?>
2.Write a program to implement multiple inheritance.
<?php
class Geeks
{
public function sayhello()
{
echo "Hello";
echo "<br>";
}
}
trait forGeeks
{
public function sayfor()
{
echo " Geeks";
echo "<br>";
}
}
class Sample extends Geeks
{
use forGeeks;
public function geeksforgeeks()
{
echo "GeeksforGeeks";
echo "<br>";
}
}
class Example
$this->Name = $UserName;
$this->Age = $UserAge;
echo "<br>";
?>