For loop issue

I’m trying to populate a drop down list box based on array contents. The first option must be associated with the 1 value. What’s the problem with the following code?


<?php
echo '<select id="t">';
$arr = array(
	'a',
	'b',
	'c',
	'd',
);
for ($i = 1; $i <= 4; $i++) {
	echo  '<option value="' .$i. '">' .$arr[$i--]. '</option>';
}
echo '</select>';
?>

Use foreach to loop through the array

Solved. Thanks, guido.

Just so you are aware, PHP arrays without associative keys start numbering at 0, not 1. In your example, ‘a’ is position 0, ‘b’ is position 1, ‘c’ is position 2, and ‘d’ is position 3.