Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Class: CO6I – A/B Academic Year: 2020-2021

Experiment – 4
Title: Write a PHP program for creating and manipulating-
a. Indexed array
b. Associative array
c. Multidimensional array
Roll No.: 29 Name: Mehraan Khan

1. Aim: Write a PHP program for creating and manipulating-


a. Indexed array
b. Associative array
c. Multidimensional array

2. Resources Used:
Personal Computer, Windows XP or above operating system, XAMPP (PHP,
APACHE, MYSQL), Microsoft Word

3. Theory:

Page 1 of 6
Page 2 of 6
Page 3 of 6
Page 4 of 6
4. Program Code:
a. Write PHP script to display fruits name stored in an indexed array.
<?php
$fruits = array("Apple", "Mango", "Banana","Grapes");
$arrlength = count($fruits);
for($x = 0; $x < $arrlength; $x++) {
echo $fruits[$x];
echo "<br>";
}
?>

b. Write PHP script to display name and age of students stored in an associative
array.
<?php
$age = array("Mehraan"=>"18" ,"Advay"=>"17", "Harsh"=>"20"
,"sam"=>"19");
foreach($age as $x => $x_value)
{
echo "Name=" . $x . ", Age=" . $x_value;
echo "<br>";
}
?>

Page 5 of 6
c. Write PHP script to display marks of 3 subjects of 3 students using
multidimensional array.
<?php
$marks = array("Mehraan" => array ("physics" => 39,"maths" =>
30,"chemistry" => 39),
"Aksh" => array ("physics" => 30,"maths" => 39,"chemistry" => 29),
"Sam" => array ("physics" => 31,"maths" => 22,"chemistry" => 38),);
echo "Marks for Mehraan in physics : " ;
echo $marks['Mehraan']['physics'] . "<br />";
echo "Marks for Aksh in maths : ";
echo $marks['Aksh']['maths'] . "<br />";
echo "Marks for Sam in chemistry : " ;
echo $marks['Sam']['chemistry'] . "<br />";
?>

6. Conclusion: Hence we have learned to write a PHP program for creating and
manipulating-
a. Indexed array
b. Associative array
c. Multidimensional array

Page 6 of 6

You might also like