Tools, FAQ, Tutorials:
Passing Variables by References in PHP
How To Pass Variables By References? in PHP?
✍: FYIcenter.com
You can pass a variable by reference to a function by taking the reference of the original variable, and passing that reference as the calling argument. Here is a PHP script on how to use pass variables by references:
<?php function swap($a, $b) { $t = $a; $a = $b; $b = $t; } $x = "PHP"; $y = "JSP"; print("Before swapping: $x, $y\n"); swap(&$x, &$y); print("After swapping: $x, $y\n"); ?>
This script will print:
Before swapping: PHP, JSP After swapping: JSP, PHP
As you can see, the function modified the original variable.
Note that call-time pass-by-reference has been deprecated. You need to define arguments as references. See next tip for details.
⇒ Defining an Argument as a Reference in PHP
⇐ Variables Are Passed by Values in PHP
2016-12-24, 1609🔥, 0💬
Popular Posts:
How to read RSS validation errors at w3.org? If your RSS feed has errors, the RSS validator at w3.or...
Can Two Forms Be Nested? Can two forms be nested? The answer is no and yes: No. You can not nest two...
How To Merge Cells in a Column? If you want to merge multiple cells vertically in a row, you need to...
How to install .NET Framework in Visual Studio Community 2017? I have the Visual Studio Installer in...
Where to find tutorials on API Management Services at Azure Portal? Here is a list of tutorials to a...