Since they intend to modify the value, getting it as a reference is clever.
$array = array("one" => 1, "two" => 2, "three" => 3, "four" => 4, "five" => 5);
foreach($array as $key => &$val) {
$val += 1;
}
Will add 1
to all values.
If you did:
foreach($array as $key => $val) {
$val += 1;
}
Nothing would happen.
I strongly disagree that it is the best way though. I much prefer to see:
foreach($array as $key => $val) {
$array[$key] += 1;
}
because it's much more straightforward. I'll gladly believe it doesn't perform as well, but I also don't care (unless there is a reason to start optimizing).
It's also worth mentioning that using references can lead to strange situations, such as: PHP reference causes data corruption
PS. I didn't downvote. I'm getting really annoyed by people downvoting and not leaving a comment.