You can also give array keys names, instead of numbers.
These are called associative arrays. Here is an example of an
associative array:
<?php
|
|
The above creates a variable that holds an associative array with some information about me.
Notice the differences in how associative arrays are created compared to normal arrays.
You still separate each item by commas, but in associative arrays you specify the key name, followed by the value:
key => value
You can add items to exisiting associative arrays too,
here's an example of how this is done:
<?php
|
|
That will add an array item with the key 'age' and the value '16' to the array. The array now looks like this:
Array
|
|
pretty easy huh? It's easy to access the information in an associative array too...
You access associative arrays much like you do normal arrays, the only difference is with the keys, instead of number you use the key names. For example:
<?php
|
|
The above code will have the following output:
Hello, my name is Ron. Visit my website: ronsguide.com. You can contact me at ron@ronsguide.com.
Hopefully this tutorial helped you to understand arrays and associative arrays a little better.
If you have any questions feel free to ask using the "Discuss this tutorial" link in the right column, under "Tutorial Options."

| Discuss Tutorial: Utilizing Arrays | 5 Comments |

Nice tutorial
