[SOLVED]display array inline

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

[SOLVED]display array inline

Post 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.
Last edited by facets on Sun May 13, 2007 5:13 am, edited 1 time in total.
Sparky
Forum Newbie
Posts: 11
Joined: Sat May 12, 2007 10:54 am

Post 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
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post by facets »

Yes. Always 2 elements.
Bingo. That did the job.

Thanks.
Post Reply