View Single Post
Old 12-18-2013, 05:38 AM   #3
lampdev112
Registered User
 
Join Date: Dec 2013
Posts: 30
Creating Associative Arrays gives you a good way to use labels as the key in the array items instead of using numbered keys that increment automatically. This way you can use a word that has meaning to you as key.

This is how we create an Associative Array holding item names(labels) and their prices:
<?php
// create an associative array that is a cart holding items and prices
$cart_array = array(
"cereal" => "5.00",
"coffee beans" => "2.50",
"bananas" => "3.50",
"onion" => "1.00",
"lettuce" => "2.40",
"tomato" => "1.00",
);
// and here is how you can output any key's value you choose
echo "Bananas cost $" . $cart_array["bananas"] . " at this store.";
echo "<br /><br />";
// And here is how you can print the whole array for viewing and debugging
print_r($cart_array);
?>
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
lampdev112 is offline   Reply With Quote