I have seen an ampersand symbol before a variable in foreach. I know the ampersand is used for fetching the variable address which is defined earlier.
I have seen a code like this:
<?php
$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
$value = $value * 2;
}
// $arr is now array(2, 4, 6, 8)
unset($value); // break the reference with the last element
?>
I just need to know the use of & before $value. I haven't seen any variable declared before to fetch the variable address.
Please help me why its declared like this. Any help would be appreciated.