For loop with 2D array

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
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

For loop with 2D array

Post by Sindarin »

I have an array,

$application_languages = array('en' => 'English', 'el' => 'Greek');

and try to show those in a for loop, I need the 'en', 'el' etc. but will also need 'English', 'Greek' values...

This code will cause errors,

Code: Select all

<?php for($i=0;$i<count($application_languages);$i++) { ?>
<div class="form-line">
	<label><?php echo s_title; ?> (<?php echo $application_languages[$i][$i]; ?>)</label>
	<input type="text" class="input-text-medium" name="title_<?php echo $application_languages[$i][$i]; ?>" />
</div>
<?php } ?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: For loop with 2D array

Post by Celauran »

Code: Select all

foreach ($application_languages as $key => $value)
No?

Also, that's not a two-dimensional array.
Post Reply