Modify arrays in form alter I'am having an issue which i cannot understand it , for example i have the following lines:

$form['field']['und'][0]['#type'] = 'select';
$form['field']['und'][1]['#type'] = 'select';
$form['field']['und'][2]['#type'] = 'select';
$form['field']['und'][3]['#type'] = 'select';


it works as expected , but if i try to change this hard coded method to :

foreach ($form['field']['und'] as $field)
            $field['#type'] = 'select';


it is not working anymore as expected...After a call like

 print render($form['field']);


for the first paragraph the result is good , as expected. But for the second paragraph it is not working anymore, the result is like nothing has been modified in the array. In the dsm($form) result either way the value of '#type' key is modified... I cannot understand the behavior. Please help!
Like PHP documentation says:
In order to be able to directly modify array elements within the loop precede $value with &amp;. In that case the value will be assigned by reference.

&lt;?php
$arr = array(1, 2, 3, 4);
foreach ($arr as &amp;$value) {
    $value = $value * 2;
}
// $arr is now array(2, 4, 6, 8)
unset($value); // break the reference with the last element
?&gt;


http://php.net/manual/en/control-structures.foreach.php