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, 1681🔥, 0💬
Popular Posts:
Where to find tutorials on Microsoft Azure services? Here is a large collection of tutorials to answ...
How to build a test service operation to dump everything from the "context.Request" object in the re...
How to dump (or encode, serialize) a Python object into a JSON string using json.dumps()? The json.d...
How to reinstall npm with a node version manager? I am getting permission errors with the current ve...
How To Set session.gc_divisor Properly in PHP? As you know that session.gc_divisor is the frequency ...