I got to this page about references and I'm lost, I really don't understand what they are about..
I suggest reading the PHP Manual on References Explained
Can somone give me a practical use for this so I might understand what it would be used for...
One practical use is mentioned in Hudson's online book: to avoid unnecessary copying of objects that could well be expensive to copy.
Another practical use is for propagating changes to an argument passed to a function to its caller. For example, you might want to write a function that swaps its arguments. You could write:
function swap($a, $b) {
$t = $a;
$a = $b;
$b = $t;
}
Unfortunately, that will not work. All you would be doing is swapping the local variables $a and $b. So if you to write:
$x = 1;
$y = 2;
swap($x, $y);
You would find that after swap() is called, $x is still 1 and $y is still 2. Even if $x and $y contained objects, they still would not be swapped, since all that would happen is that their references in swap() would be swapped. To make it work, you have to use pass by reference:
function swap(&$a, &$b) {
$t = $a;
$a = $b;
$b = $t;
}