Tools, FAQ, Tutorials:
Defining an Argument as a Reference in PHP
Can You Define an Argument as a Reference Type? in PHP?
✍: FYIcenter.com
You can define an argument as a reference type in the function definition. This will automatically convert the calling arguments into references. Here is a PHP script on how to define an argument as a reference type:
<?php
function ref_swap(&$a, &$b) {
$t = $a;
$a = $b;
$b = $t;
}
$x = "PHP";
$y = "JSP";
print("Before swapping: $x, $y\n");
ref_swap($x, $y);
print("After swapping: $x, $y\n");
?>
This script will print:
Before swapping: PHP, JSP After swapping: JSP, PHP
⇒ Passing Arrays to Function in PHP
⇐ Passing Variables by References in PHP
2016-12-24, ∼2109🔥, 0💬
Popular Posts:
How To Break a File Path Name into Parts in PHP? If you have a file name, and want to get different ...
What is the "__init__()" class method? The "__init__()" class method is a special method that will b...
How to run PowerShell Commands in Dockerfile to change Windows Docker images? When building a new Wi...
How to use the "set-variable" Policy Statement to create custom variables for an Azure API service o...
What are the differences of Differences of evaluateTransaction() and submitTransaction() of the fabr...