Tools, FAQ, Tutorials:
Variables Are Passed by Values in PHP
How Variables Are Passed Through Arguments? in PHP?
✍: FYIcenter.com
Like more of other programming languages, variables are passed through arguments by values, not by references. That means when a variable is passed as an argument, a copy of the value will be passed into the function. Modifying that copy inside the function will not impact the original copy. Here is a PHP script on passing variables by values:
<?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: PHP, JSP
As you can see, original variables were not affected.
⇒ Passing Variables by References in PHP
⇐ Passing an Argument to a Function in PHP
2016-12-24, ∼2703🔥, 0💬
Popular Posts:
What Happens If One Row Has Missing Columns? What happens if one row has missing columns? Most brows...
How To Truncate an Array in PHP? If you want to remove a chunk of values from an array, you can use ...
How to use the RSS Online Validator at w3.org? You can follow this tutorial to learn how to use the ...
How to add request body examples to my Azure API operation to make it more user friendly? If you hav...
How to use the "@(...)" expression in Azure API Policy? The "@(...)" expression in Azure API Policy ...