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

Practical No 4

The document provides PHP code examples for creating and manipulating different types of arrays: indexed, associative, and multi-dimensional. It includes code snippets for each array type along with their respective outputs. The examples demonstrate how to store and display data using PHP arrays.

Uploaded by

Sayali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Practical No 4

The document provides PHP code examples for creating and manipulating different types of arrays: indexed, associative, and multi-dimensional. It includes code snippets for each array type along with their respective outputs. The examples demonstrate how to store and display data using PHP arrays.

Uploaded by

Sayali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Practical No 4

Que 1 – Write a PHP program for creating and manipulating –

a. Indexed Array

<?php
//Indexed Array
$seasons = array('Summer','Rainy','Winter', 'Autumn');

for($i=0; $i<count($seasons); $i++)


echo "$seasons[$i] <br>";
?>

Output –

b. Associative Array

<?php
//Associative Array
$emp = array(
'id' => 123,
'name' => 'Shantanu Gaikwad',
'email' => '[email protected]',
'salary' => 100000);

echo "Employee Details <hr>";


echo "Id: ".$emp['id']."<br>";
echo "Name: ".$emp['name']."<br>";
echo "Email: ".$emp['email']."<br>";
echo "Salary: ".$emp['salary']."<br>";
?>

Output –

c. Multi – Dimensional Array

<?php
//Multidimensional Array

$score = array(
'Ben' => array(
'Chemistry' => 88,
'Physics' => 90,
'Math' => 95),
'Max' => array(
'Chemistry' => 80,
'Physics' => 85,
'Math' => 85));

echo "Shantanu: <br>";


echo "Chemistry: ".$score['Ben']['Chemistry']."<br>";
echo "Physics: ".$score['Ben']['Physics']."<br>";
echo "Math: ".$score['Ben']['Math']."<hr>";

echo "Riya: <br>";


echo "Chemistry: ".$score['Max']['Chemistry']."<br>";
echo "Physics: ".$score['Max']['Physics']."<br>";
echo "Math: ".$score['Max']['Math'];
?>

Output –

You might also like