Associative Arrays use an ID key that is not necessarily a numeric value. Here is an example: $mystats = array(“Weight”=>900, “Looks”=>1, “IQ”=>12); Another way to create an associative array is like this: $mystats['Weight'] = 900; $mystats['Looks'] = 1; $mystats['IQ'] = 12; If it still isn't clear, this following coding example should make it so: <html> <body> <?php $mystats['Weight'] = 900; $mystats['Looks'] = 1; $mystats['IQ'] = 12; echo “I weigh “ . $mystats['Weight'] . “pounds.”; } ?> The above code would result in the following: I weigh 900 pounds. As you can see, we call on the index (in this instance "Weight") to retrieve how much I weigh, which prints the value 900. If I had called on "Looks" it would have printed 1, and so forth. So instead of referencing the values in the array with numbers, we just did it with word labels to make it easier to remember and understand (you wouldn't label your files in a file cabinet with numbers, unless you were The Count from Sesame Street that is).
blog comments powered by Disqus |
|
|
|
|
|
|
|