+ 1
Can anyone please explain me this code, why $name came instead of $names
<?php $names = array("John", "David", "Amy"); foreach ($names as $name) { echo $name.'<br />'; } ?>
1 Antwort
+ 4
foreach executes as many times as there are values in the given array ($names). Each time it's run it stores the current value in the given variable ($name). $name can then be used inside the foreach-block.
Also, $name is probably read-only. (No gurantee.)