PHP List of Experiments
PHP List of Experiments
PHP Experiments
echo "Hello<br>Welcome";
?>
$integer1 = 20;
$floating1 = 30.2351;
$integer2 = 30;
$floating2 = 13.8943;
$check;
$y = "Condition is false";
$x = "Condition is true";
echo $a."<br>";
$integer2 = 20;
$a = ($check) ? $x:$y;
echo $a."<br>";
?>
function fibonacci($i)
$sum = 0;
$b = 1;
$a = 0;
for($j=0;$j<$i-2;$j++)
$sum =$a + $b ;
$a = $b;
$b = $sum;
fibonacci(25);
?>
Q.4 Write PHP script to demonstrate Variable function
Code –
<?php
$y = "1234.56789Hello";
$arr = array("Indore","Bhopal","Ujjain","Dewas");
$x = 7832;
$a = 20;
$c ;
$b = "hello";
echo "<br>".gettype($a);
echo "<br>".isset($a)."<br>"; //used to check whether the variable has been declared and initialized
or not
if(isset($c))
echo "<br>".strval($x); //$x will be returned as string but its datatype will remain integer(applied for
all datatypes)
echo "<br>".floatval($y); //$y will be returned as float and if its not starting with a number then it
will return 0
print_r($arr);
?>
echo strcmp($comp1,$comp2);
echo "<br>".strcasecmp($comp1,$comp2);
echo "<br>".strrev($comp1);
echo "<br>".stristr($comp2,"o")."<br>";
print("Hello world");
echo "<br>".substr("aibohphobia",4);
echo "<br>".trim($comp2,"held");
echo "<br>".rtrim($comp2,"rld");
echo "<br>".ltrim($comp2,"hel");
echo "<br>".strlen($comp2);
echo "<br>".strtoupper($comp2);
echo "<br>".ord("A");
echo "<br>".chr(65);
?>
$birds = array("Eagle","Sparrow","Pigeon","Vulture","Ostrich");
$numbers = array(23,45,234,53,76,543,23,445,24);
echo count($birds)."<br>";
list($a,$b,$c,$d,$e) = $birds;
echo "There are many birds for example: $a, $b, $c, $d and $e<br>";
echo var_dump(in_array("Eagle",$birds))."<br>";
echo current($birds)."<br>";
echo next($birds)."<br>";
echo end($birds)."<br>";
echo prev($birds)."<br>";
//print_r (each($cars)); This function has been removed from PHP 7.2
sort($birds);
print_r ($birds);
echo "<br>";
print_r (array_merge($birds,$cars));
$merged = array_merge($birds,$cars);
echo "<br>";
print_r ($merged);
echo "<br>";
print_r (array_reverse($birds));
echo "<br>";
sort($numbers);
print_r ($numbers);
?>