|
Free
PHP Tutorials
|
![]() |
home |
Stay
at Home and Learn
|
|||||
PHP Tutorials |
||||||
|
PHP Arrays - Using Text as Keys
Your arrays keys don't have to be numbers, as in the previous section. They can be text. This can help you remember what's in a key, or what it's supposed to do. When you use text for the keys, you're using an Associative array; when you use numbers for the keys, you're using a Scalar array. Here's an array that sets up first name and surname combinations: $full_name = array( ); $full_name["David"]
= "Gilmour"; Fans of a certain band will know exactly who these people are! But look at the keys and values now: David => "Gilmour", This is easier to remember than this: 0 => "Gilmour", To access the values in an Associative array, just refer to the Key name: print $full_name["David"]; |