Hey all!
I've got a question about looping through arrays that aren't named sequentially.. for example, you can do this: -
<?php
$var[] = "a";
$var[] = "b";
$var[] = "c";
$var[] = "d";
$var[] = "e";
$var[] = "f";
for($k=0; $k<count($var); $k++) {
echo $var[$k];
}
// outputs abcdef
?>
But how would you make sure you get every element, for example .. if you had this: -
<?php
$var[1] = "a";
$var[3] = "b";
$var[2] = "c";
$var[5] = "d";
$var[6] = "e";
$var[9] = "f";
for($k=0; $k<count($var); $k++) {
echo $var[$k];
}
// outputs acbd
?>
Or, likewise, if the numbers in $var[NUMBER] were text, such as $var['name1'] $var['name2'], how can these be looped through?
Thanks very much in advance for any help! 😃