PHP References Explained


 

PHP References Explained

This tutorial covers three basic operations performed by references, assigning values by references, passing by references, returning by references etc. In PHP references means to access the same variable by two or more different names.

This tutorial covers three basic operations performed by references, assigning values by references, passing by references, returning by references etc. In PHP references means to access the same variable by two or more different names.

References In PHP:

What PHP References are?

In PHP references  means to access the same variable by two or more different names. References are not like  C pointers means these are not for storing address or any other pointer arithmetic. The references can be linked to hardlinking in Unix filesystem. 

This tutorial covers three basic operations performed by references, assigning values by references, passing by references, returning by references etc.

Assign by reference:

PHP Reference Example:

<?php

$var1=12;

$var2=&$var1;

echo "Value of \$var1:".$var1."<br/>";

echo "Value of \$var2:".$var2."<br/>";

?>

Output:

Value of $var1:12
Value of $var2:12

Ads