Hi,
I have just started learning PHP and I think that this may be a very stupid question (especially since I can't find anything on it here or on Google), but I'm having some problems with arrays.
I'm in Chapter Two of the Wrox Beginning PHP5 book (2004), and I am trying to write a function that calls values from the array. When I use, eg., $my_named_array["dog"], it works fine, but when I use exactly the same code but $my_named_array[0], no result is returned.
Below is the code for the working function:
Code:
<?php
$my_named_array = array("pig" => "ralph", "cat" => "scuzz", "bird" => "ickerbod");
$my_pig = $my_named_array["pig"];
$my_cat = $my_named_array["cat"];
$my_bird = $my_named_array["bird"];
echo "My pig is named $my_pig, my cat is named $my_cat and my bird is named $my_bird.";
?>
And for the non-working function:
Code:
<?php
$my_named_array = array("pig" => "ralph", "cat" => "scuzz", "bird" => "ickerbod");
$my_pig = $my_named_array[0];
$my_cat = $my_named_array[1];
$my_bird = $my_named_array[2];
echo "My pig is named $my_pig, my cat is named $my_cat and my bird is named $my_bird.";
?>
Oh, and on a tangential note, can I use capitals in arrays? And if not, is there a way to force capitals when echoing?
Thanks in advance,
JaneDean