Page 1 of 1

[SOLVED]display array inline

Posted: Sun May 13, 2007 3:44 am
by facets
I've been banging my head for too long on this one.

I'd like to dynamically create the following, but can't work it out.

Code: Select all

echo $toXML[0][0]." = ".$toXML[0][1]."<br />";
echo $toXML[1][0]." = ".$toXML[1][1]."<br />";
I have tried variants of this but can only get them display below each other not side by side.

Code: Select all

foreach ($toXML as $outer_key => $single_array) {
	foreach ($single_array as $inner_key => $value) {
		echo "<br>" . $value;
	}
}
I am constantly fighting with Arrays. Any ideas?

ta, Will.

Posted: Sun May 13, 2007 4:34 am
by Sparky
Does your inner array always have two elements? ([0] and [1])? If so, you don't need to ForEach that array:

Code: Select all

foreach ($toXML as $outer_key => $single_array) 
        {
                echo $single_array[0].' = '.$single_array[1].'<br>';
        }
}
HTH

Posted: Sun May 13, 2007 5:13 am
by facets
Yes. Always 2 elements.
Bingo. That did the job.

Thanks.