[!--quoteo(post=354954:date=Mar 14 2006, 05:27 PM:name=redbullmarky)--][div class=\'quotetop\']QUOTE(redbullmarky @ Mar 14 2006, 05:27 PM)
when arrays were first explained to me, i was told to imagine a load of boxes lined up either in a line or a grid. each one had a name, a number, or both. each box could be referred to by its name OR number.
this bit sets up 5 boxes, labelled 'array1' through to 'array5'. each one is given start contents, which in this case is a letter from A-E.
the 'while' statement simply kicks off a loop that will keep repeating while the condition remains true.
as for this:
i really don't know what youre trying to achieve. i even tried it myself out of curiosity but it didnt work, so i'm guessing it was a bit of guesswork on your behalf, or some code that your course teacher gave you. either way, it seems really horrible (although if there's a specific purpose to doing it this way, i'd love to know - anyone?)
but in a nutshell, all an array is is loads of variables grouped by the same name. here's 3 examples:
// set up a variable (1 box) called 'a', stick the number 5 in it
$a = 5;
// set up 5 boxes. by default, these will be labelled 0-4 (labels start at 0) as i have not specifically named them otherwise, and put some even numbers in it.
// these boxes can be accessed by $a - $a. eg $a contains '6'
$a = array(2, 4, 6, 8, 10);
// do the same as above, but give each box a better name
// these boxes can be accessed with $a['first'] - $a['fifth']
$a = array("first"=>2, "second"=>4, "third"=>6, "fourth"=>8, "fifth"=>10);
so if i'm getting this right, and your example needs you to show the box name and the box's value, just use 'foreach', which basically is a nice way of automatically going through each box of an array one by one:
foreach($myarray as $boxname=>$boxvalue)
echo $boxname.' is '.$boxvalue.'<br>';
hope that helps
Thank you for the example its grate and better then the video training i am using and a lot easer.
I was told to use list and each stsement but i think your code is better, is the statement list and each a statement i realy need to study in a array or is your exmple just as good or better thank you so much.