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

PHP PracticalSET2 KD

Uploaded by

hetmp2006
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)
29 views15 pages

PHP PracticalSET2 KD

Uploaded by

hetmp2006
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/ 15

Practical Set 2 SUB: PHP

Practical : 1
AIM: Write PHP Script to demostrate assosiative array

<?php

$a=array("Name"=>"krish","Surname"=>"Patel","class"=>"C","batch"=>"2");

foreach($a as $k=>$v){ echo $k." :".$v."<br>";

?>

Output:-

NAME: PATEL KRISH DAHYABHAI

ENROLL NO : 22171341102

IOT CE-C-52

15 | P a g e
Practical Set 2 SUB: PHP
Practical : 2
AIM: Write PHP script for cheacking that given number is prime or
not using user-defined function
<?php

function primeorcomp($a)

if($a%2==0||$a%3== 0||$a%4== 0||$a%5==0)

echo "$a is composite <br>";

else

echo "$a is prime <br>";

primeorcomp(10);

primeorcomp(11);

?>

Output:-

NAME: PATEL KRISH DAHYABHAI

ENROLL NO : 22171341102

IOT CE-C-52

16 | P a g e
Practical Set 2 SUB: PHP Practical
:
AIM: Write PHP script to swap two number using user-defined
function. (call by value and call by reference)

<?php

function cbv($n1,$n2)

$c=$n1;

$n1 = $n2;

$n2 = $c;

function cbr(&$n1,&$n2)

$c=$n1;

$n1 = $n2;

$n2 = $c;

$a=10; $b=20; echo"call by value

swap before:$a,$b <br>";

cbv($a,$b); echo"call by value swap after:

$a,$b <br>"; echo"call by refrence swap

before:$a,$b <br>"; cbr($a,$b);

echo"call by refrence swap before:$a,$b <br>";

?>

NAME: PATEL KRISH DAHYABHAI

ENROLL NO : 22171341102

IOT CE-C-52

17 | P a g e
Practical Set 2 SUB: PHP

Output:-

NAME: PATEL KRISH DAHYABHAI

ENROLL NO : 22171341102

IOT CE-C-52

18 | P a g e
Practical Set 2 SUB: PHP Practical
:
AIM: Write PHP script to demonstrate Variable function.
<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Document</title>

</head>

<body>

<?php

$a = 27;

$b = "Exlaso"; $bool

= true;

var_dump($a);

echo "<br>";

var_dump($b);

echo "<br>";

is_null($a); echo "Convert

$a to String"; settype($a,

"string"); echo "<br>"; echo

var_dump($a); echo "<br>";

echo "<br>"; ?>

</body>

Output:-

NAME: PATEL KRISH DAHYABHAI

ENROLL NO : 22171341102

IOT CE-C-52

19 | P a g e
Practical Set 2 SUB: PHP

5
AIM: Write PHP script to demonstrate String function.

NAME: PATEL KRISH DAHYABHAI

ENROLL NO : 22171341102

IOT CE-C-52

20 | P a g e
Practical Set 2 SUB: PHP Practical
:
<?php echo"<b>CHR string

function:</b>"; echo chr(52);

echo"<br>"; echo chr(103); echo"<br>";

echo chr(55); echo"<br>";

echo"<b>STRCMP string function:</b>";

echo strcmp("krish","krish");

echo"<br>"; echo strcmp("hello","hello

world"); echo"<br>"; echo

strcmp("kp","knp"); echo"<br>";

echo"<b>STRLEN string function:</b>";

echo strlen("krish");

echo"<br>"; echo strlen("ganpat

university"); echo"<br>";

echo"<b>STRTOUPPER string function:</b>";

echo strtoupper("krish"); echo "<br>";

NAME: PATEL KRISH DAHYABHAI

ENROLL NO : 22171341102

IOT CE-C-52

21 | P a g e
Practical Set 2 SUB: PHP

echo strtoupper("class:c"); echo

"<br>"; echo"<b>TRIM string

function:</b>"; echo trim (" krish

patel");

echo "<br>"; echo

trim("hello","0"); echo

"<br>";

?>

Output:-

NAME: PATEL KRISH DAHYABHAI

ENROLL NO : 22171341102

IOT CE-C-52

22 | P a g e
Practical Set 2 SUB: PHP Practical
:
6
AIM: Write PHP script to demonstrate Date function.
<?php

echo date ("d.m.y")."<br>"; echo

date ("D/M/Y")."<br>"; echo date

("D/m/y")."<br>"; echo date

("d/M/y")."<br>"; echo date

("d/m/Y")."<br>"; var_dump

(checkdate (9,11,2006)); var_dump

(checkdate (12,31,-400)); echo

time();

?>

Output:-

NAME: PATEL KRISH DAHYABHAI

ENROLL NO : 22171341102

IOT CE-C-52

23 | P a g e
Practical Set 2 SUB: PHP

Practical : 7
AIM: Write PHP script to demonstrate Math function.
<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Document</title>

</head>

<body> <?php

echo pow(20,3);

echo '</br>'; echo

sqrt(144); echo

'</br>'; echo

round(30.23); echo

'</br>'; echo abs(-

12.29)

?>

</body>

</html>

Output:-

NAME: PATEL KRISH DAHYABHAI

ENROLL NO : 22171341102

IOT CE-C-52

24 | P a g e
Practical Set 2 SUB: PHP
Practical : 8

AIM: Write PHP script to demonstrate Array


function
<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Document</title>

</head>

<body>

<?php

$arr = array("K","R","I","S","H");

$arr1 = $arr;

$arr2 = array("","I","S"," ","G","O","O","D"," ","B","O","Y");

echo join($arr)." Has ".count($arr)." Letters "; echo '</br>';

sort($arr); echo "Sorting in Ascending order<br>";

foreach($arr as $a){ echo $a;

echo '</br>'; rsort($arr); echo "Sorting

in Descending order<br>"; foreach($arr

as $a){

$a;

NAME: PATEL KRISH DAHYABHAI

ENROLL NO : 22171341102

IOT CE-C-52

25 | P a g e
Practical Set 2 SUB: PHP

echo "</br>";

$arr3 = array_merge($arr1,$arr2);

foreach ($arr3 as $value) { echo"

$value";

?>

</body>

</html>

Output:-

NAME: PATEL KRISH DAHYABHAI

ENROLL NO : 22171341102

IOT CE-C-52

26 | P a g e
Practical Set 2 SUB: PHP

Practical : 9
AIM: Write PHP script to demonstrate File function.
<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=, initial-scale=1.0">

<title>Document</title>

</head>

<body>

<?php

$arr = file("krish.txt");

foreach ($arr as $value) {

echo $value; echo

"<hr>";

?>

</body>

</html>

NAME: PATEL KRISH DAHYABHAI

ENROLL NO : 22171341102

IOT CE-C-52

27 | P a g e
Practical Set 2 SUB: PHP
krish.txt :- name :

Patel krish n. Class:

C - 52

E.no : 22171341103

SUB : PHP

NAME: PATEL KRISH DAHYABHAI

ENROLL NO : 22171341102

IOT CE-C-52

28 | P a g e

You might also like