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, ∼2880🔥, 0💬
Popular Posts:
Where to find tutorials on RSS specifications? I want to learn it to describe my API services. Here ...
How to create a navigation file like navigation.xhtml for an EPUB 3.0 book? At least one navigation ...
What validation keywords I can use in JSON Schema to specifically validate JSON Array values? The cu...
Where can I download the EPUB 2.0 sample book "The Problems of Philosophy" by Lewis Theme? You can f...
How to use "json-to-xml" Azure API Policy Statement? The "json-to-xml" Policy Statement allows you t...