0% found this document useful (0 votes)
60 views

PHP List of Experiments

This document contains 6 questions and corresponding PHP code snippets demonstrating various PHP functions and concepts such as: 1) Displaying a welcome message using echo. 2) Demonstrating arithmetic, comparison, and logical operators using variables and conditions. 3) Printing the Fibonacci series using a function. 4) Demonstrating variable functions like gettype(), settype(), isset(), etc. 5) Demonstrating string functions like strcmp(), strrev(), str_replace(), etc. 6) Demonstrating array functions like count(), in_array(), current(), sort(), array_merge(), etc.

Uploaded by

Paritosh Belekar
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)
60 views

PHP List of Experiments

This document contains 6 questions and corresponding PHP code snippets demonstrating various PHP functions and concepts such as: 1) Displaying a welcome message using echo. 2) Demonstrating arithmetic, comparison, and logical operators using variables and conditions. 3) Printing the Fibonacci series using a function. 4) Demonstrating variable functions like gettype(), settype(), isset(), etc. 5) Demonstrating string functions like strcmp(), strrev(), str_replace(), etc. 6) Demonstrating array functions like count(), in_array(), current(), sort(), array_merge(), etc.

Uploaded by

Paritosh Belekar
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/ 5

Name : Paritosh Belekar

Enroll. No. : 20100BTCSICS07343

PHP Experiments

Q.1 Write a PHP script to display Welcome message.


Code –
<?php

echo "Hello<br>Welcome";

?>

Q.2 Write a PHP script to demonstrate arithmetic operators, comparison


operator, and logical operator.
Code –
<?php

$integer1 = 20;

$floating1 = 30.2351;

$integer2 = 30;

$floating2 = 13.8943;

$check;

$y = "Condition is false";

$x = "Condition is true";

echo $integer1 + $integer2."<br>";

echo $integer1 - $integer2."<br>";

echo $integer1 / $integer2."<br>";

echo $integer1 * $integer2."<br>";

echo $integer1 % $integer2."<br>";

echo $integer1 ** $integer2."<br>";

$check = $integer1 == $integer2;

echo "Condition check ".$check."<br>";

echo "Not Condition check ".!($check)." This is end<br>";


$a = ($check) ? $x:$y;

echo $a."<br>";

$integer2 = 20;

$check = $integer1 == $integer2;

echo "Condition check ".$check."<br>";

echo "Not Condition check ".!($check)."This is end<br>";

$a = ($check) ? $x:$y;

echo $a."<br>";

?>

Q.3 Write PHP Script to print Fibonacci series.


Code –
<?php

function fibonacci($i)

$sum = 0;

$b = 1;

$a = 0;

echo "$a $b ";

for($j=0;$j<$i-2;$j++)

$sum =$a + $b ;

echo $sum." ";

$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 gettype($a)."<br>".gettype($b); //used to get datatype of variable

settype($a,"string"); //used to change the datatype of a variable

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 "\$c is set/declared";

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

echo "<br>".intval($y)."<br>"; //$y will be returned as integer

print_r($arr);

?>

Q.5 Write PHP script to demonstrate string function.


Code –
<?php

$comp1 = "Hello world";

$comp2 = "hello world";

echo strcmp($comp1,$comp2);

echo "<br>".strcasecmp($comp1,$comp2);
echo "<br>".strrev($comp1);

echo "<br>".str_replace("Hello","New word",$comp1);

echo "<br>".stristr($comp2,"o")."<br>";

print("Hello world");

echo "<br>".strpos("This is to check the position of any given string","the");

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>".strtolower("HEllO WoRld");

echo "<br>".ord("A");

echo "<br>".chr(65);

?>

Q.6 . Write PHP script to demonstrate Array functions.


Code –
<?php

$birds = array("Eagle","Sparrow","Pigeon","Vulture","Ostrich");

$cars = array("Tata","Volkswagen","Ford","Mahindra","Maruti Suzuki","Skoda");

$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);

?>

You might also like