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

PHP Programs

The document describes a PHP program to perform various array operations like search, difference, combine, and sorting. It also includes programs to calculate factorials using different loops and a program to create an inventory table using associative arrays.

Uploaded by

riohaven45
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)
43 views

PHP Programs

The document describes a PHP program to perform various array operations like search, difference, combine, and sorting. It also includes programs to calculate factorials using different loops and a program to create an inventory table using associative arrays.

Uploaded by

riohaven45
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/ 24

EX.

NO:
ARRAY OPERATIONS
DATE:

AIM:
Write a PHP program to perform array operations like array search,array difference and
array combine,array matching and sorting.

PROCEDURE:
 Start the program.
 Open a new notepad window
 Type the array operation program on notepad.
 Save the file as pgm1.php.
 Run the pgm1.php at wamp server.
 Type the following address bar.localhost/KT/pgm1.php.
 Output of pgm1.php will be displayed at local host page.
 Stop the program.

1
PROGRAM:
<body>

<?php

echo"ARRAY OPERATION<br/><br/>";

echo"*********<br/><br/>";

$a1=array("apple","orange","mango");

$a2=array("banana","grapes","mango");

echo"<br/><br/>";

echo "array search operations<br/>";

echo".............<br/>";

echo"<br/><br/>";

if(in_array("apple",$a1))

echo"search element(Apple) is present in the array";

else

echo"search element(Apple) is not present in the array";

echo"<br/><br/><br/>";

echo"Array difference<br/>";

echo"...................<br/>";

$result=array_diff($a2,$a1);

2
print_r($result);

echo"<br/><br/>";

echo"<br/><br/>";

echo"Array merging<br/>";

echo"................<br/>";

$c=array_combine($a1,$a2);

print_r($c);

echo"<br/><br/>";

echo"<br/><br/>";

echo"Array matching<br/>";

echo"................<br/>";

$match_result=array_intersect($a1,$a2);

print_r($match_result);

echo"<br/><br/>";

echo"<br/><br/>";

echo"Array sorting<br/>";

echo"...........<br/>";

sort($a1);

foreach($a1 as $s)

echo"$s<br/>";

?>

</body>

</html>

3
OUTPUT:

4
RESULT:

5
Thus the program was executed successfully.

AIM:
Write a PHP program to perform factorial calculation using if statements.

PROCEDURE:
 Start the program.
 Open the new notepad on window.
 Type the factorial program on notepad.
 Save the file as pgm2.php.
 Run the pgm2.php at wamp server.
 Type the following address bar.localhost/KT/pgm2.php.
 Output of pgm2.php will be displayed at localhost page.
 Stop the program.

EX.NO:
FACTORIAL CALCULATION USING IF STATEMENT
DATE:

6
PROGRAM:
<html>

<body>

<?php

echo"FACTORIAL CALCULATION USING IF STATEMENT<br/>";

echo"******************************************</br><br>";

function fact($n)

if($n<=1)

return 1;

else

return $n*fact($n-1);

echo`Factorial of 5 is`.fact(5);

?>

</body>

</html>

7
OUTPUT:

8
9
RESULT:
Thus the program was executed successfully.

EX.NO:
FACTORIAL CALCULATION USING WHILE
DATE: STATEMENT

AIM:
Write a PHP program to perform factorial calculation using while statements.

PROCEDURE:
 Start the program.
 Open the new notepad on window.
 Type the factorial operation on notepad.
 Save the file as pgm3.php.
 Run the pgm3.php at wamp server.
 Type the following address bar.localhost/KT/pgm3.php.
 Output of pgm3.php will be displayed at localhost page.
 Stop the program.

EX.NO:

DATE:

10
PROGRAM:
<html>

<body>

<?php

$input=5;

$fact=1;

echo"FACTORIAL CALCULATION USING WHILE STATEMENT<br><br>";

echo"*********************************************<br><br>";

while($input>0)

$fact*=$input;

$input=$input-1;

echo'The factorial of the number 5 is '.$fact

?>

11
</body>

</html>

OUTPUT:

12
RESULT:
Thus the program was executed successfully.

13
EX.NO:
FACTORIAL CALCULATION USING DO-WHILE
DATE: STATEMENT

AIM:
Write a PHP program to perform factorial calculation using do-while statements.

PROCEDURE:
 Start the program.
 Open the new notepad on window.
 Type the factorial operation on notepad.
 Save the file as pgm4.php.
 Run the pgm4.php at wamp server.
 Type the following address bar.localhost/KT/pgm4.php.
 Output of pgm4.php will be displayed at localhost page.
 Stop the program.

EX.NO:

DATE:

14
PROGRAM:
<html>

<body>

<?php

echo"FACTORIAL CALCULATION USING DO-WHILE LOOP<br><br>";

echo"*****************************************<br><br>";

$number=5;

$fact=1;

do

$fact*=$number;

$number=$number-1;

while($number>0);

echo`<br>`."The factorial of the number 5 is".$fact

?>

</body>

</html>

15
OUTPUT:

16
17
RESULT:
Thus the program was executed successfully.

EX.NO:
INVENTORY TABLE USING ASSOCIATIVE ARRAY
DATE:

AIM:
Write a PHP program to create inventory table using key and value pairs.

PROCEDURE:
 Start the program.
 Open the new notepad on window.
 Type the inventory table program on notepad.
 Save the file as pgm5.php.
 Run the pgm5.php at wamp server.
 Type the following address bar.localhost/KT/pgm5.php.
 Output of pgm5.php will be displayed at localhost page.
 Stop the program.

EX.NO:

DATE:

18
PROGRAM:
<!DOCTYPE html>

<html>

<body>

<?php

echo"INVENTORY TABLE USING ASSOCIATIVE ARRAY</br>";

echo"*****************************************</br>";

echo"<table border=3>

<tr>

<td><font color=green>ITEM NAME</td>

<td><font color=green>QUANTITY</td>

<td><font color=green>PRICE</td>

</tr>

<tr>

19
<td>Rice</td>

<td>1</td>

<td>350</td>

</tr>

<td>oil</td>

<td>1</td>

<td>150</td>

</tr>

<td>Soap</td>

<td>1</td>

<td>60</td>

</tr>

<1table>";

echo"</br></br>";

$item=array("Rice"=>"350","oil"=>"150","Soap"=>"60");

foreach($item as $x=>$x_value)

echo"key=".$x.",value=",$x_value;

echo"<br>";

?>

</body>

</html>

20
OUTPUT:

21
22
RESULT:
Thus the program was executed successfully.

23
24

You might also like