0% found this document useful (0 votes)
61 views1 page

PHP Tizag Tutorial-41 PDF

In an associative array, keys are associated with values, allowing non-numeric indexes. The document demonstrates using an associative array to store employee salaries with their names as keys and pay amounts as values. Code is shown declaring the $salaries array with names and salaries, then outputting statements echoing each employee's name and pay amount to display the associative array.

Uploaded by

Anil Kumar
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)
61 views1 page

PHP Tizag Tutorial-41 PDF

In an associative array, keys are associated with values, allowing non-numeric indexes. The document demonstrates using an associative array to store employee salaries with their names as keys and pay amounts as values. Code is shown declaring the $salaries array with names and salaries, then outputting statements echoing each employee's name and pay amount to display the associative array.

Uploaded by

Anil Kumar
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/ 1

PHP - Associative Arrays

In an associative array a key is associated with a value. If you wanted to store the salaries of your
employees in an array, a numerically indexed array would not be the best choice. Instead, we could use the
employees names as the keys in our associative array, and the value would be their respective salary.

PHP Code:
$salaries["Bob"] = 2000;
$salaries["Sally"] = 4000;
$salaries["Charlie"] = 600;
$salaries["Clare"] = 0;

echo "Bob is being paid - $" . $salaries["Bob"] . "<br />";


echo "Sally is being paid - $" . $salaries["Sally"] . "<br />";
echo "Charlie is being paid - $" . $salaries["Charlie"] . "<br />";
echo "Clare is being paid - $" . $salaries["Clare"];

Display:
Bob is being paid - $2000
Sally is being paid - $4000
Charlie is being paid - $600
Clare is being paid - $0

Once again, the usefulness of arrays will become more apparent once you have knowledge of for and
while loops.

You might also like