toodi4 wrote:Probably because arrays are my weakness.
Sounds to me you are a little afraid to take a jump into unknown water. I'll chart it out for you a little:
Look at an array as a collection box of variables. Say, I have a list of 3 variables:
$var1 = 'apple';
$var2 = 'pear';
$var3 = 'cherry';
Now, if I ask you to show the value of $var2, you have no trouble: echo $var2, which will display pear.
So.. Now I do the same, but I place them in an array:
$var = array(
1 => 'apple',
2 => 'pear',
3 => 'cherry');
Again, I ask you for the second value in the array. This sounds complex. But the nice thing is, you can directly refer to the second VALUE, by using the KEY. Whooo! Stop, I hear you say.. What is the key?
Here goes:
An array consists of the variable name (Here: var), and a number of combinations of KEYs and VALUEs, here the 1; 2; 3 and 'apple', 'pear', 'cherry'. The key identifies 'where' the VALUE is stored in the array. You indicate this with straight brackets:
the value of key 2 is: $var[2], which you can display just like before: echo $var[2].
Of course often you do not want to define the keys. In that caase you can just say:
$ var = array('apple', 'pear', 'cherry');
Please note, that then the keys start at 0! So:
echo $var[2] will display cheery (!)
You can also use strings as a key, and/or use the brackets to set specific key/value combinations:
$vars['type'] = 'fruit';
If you want to display every single variable of an array:
for($var = $key=>$value)
{
echo $key.": ".$value;
}
// Note that the expression in the foreach only tells you how you want to refer to the KEY and the VALUE. You could also use $string=>$paper, or whatever you prefer, and get exactly the same result:
for($var = $string=>$paper)
{
echo $string.": ".$paper;
}
to see the structure & values of an array:
print_r($var);
Note: print_r does not generate HTML, so view the source of your page, or add <pre> </pre> tags to see the structure. Else you see a mumble-jumble string of text.
I hope it helps to get you going.