Page 1 of 1

Foreach Code / HTML Options

Posted: Wed Sep 03, 2014 3:00 am
by donny
Hello,

can somebody show me how to make a foreach code to generate options based on an array.

My array is like this

Code: Select all

$shirtsqty = array('1'=>"1 shirt",  
			'2'=>"2 shirts",  
			'3'=>"3 shirts",
			'4'=>"4 shirts",
			'5'=>"5 shirts");  
I would like it to generate this <option value="1">1 shirt</option> etc.

thanks a lot

Re: Foreach Code / HTML Options

Posted: Wed Sep 03, 2014 5:52 am
by Celauran

Code: Select all

<select name="whatever">
	<?php foreach ($shirtsqty as $key => $value): ?>
		<option value="<?= $key; ?>"><?= $value; ?></option>
	<?php endforeach; ?>
</select>

Re: Foreach Code / HTML Options

Posted: Wed Sep 03, 2014 5:35 pm
by donny
thank you. thank you very much.