Page 1 of 1

For loop with 2D array

Posted: Sat May 19, 2012 12:25 pm
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 } ?>

Re: For loop with 2D array

Posted: Sat May 19, 2012 3:30 pm
by Celauran

Code: Select all

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

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