I've been looking everywhere for a satisfactory answer to this. Still not wrapping my head around the usefulness of the & character when used as a reference. Why would I want to use it? I learn best by example.
Here is an example taken from php.net with slight modification:
<?php
function foo(&$var)
{
$showVar = $var++;
echo $showVar;
}
$a=5;
foo($a);
?>
How is the above different from:
<?php
function foo($var) // & was removed here.
{
$showVar = $var++;
echo $showVar;
}
$a=5;
foo($a);
?>
I got the same exact result (the value of 5) when printing $var++, but according to the documentation there, it should be 6.
What is the advantage?
In any case, I'd appreciate a very lucid and even dumbed down explanation of that the benefits of using & is when referencing something.