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, ∼2192🔥, 0💬
Popular Posts:
How to use the urllib.request.Request object to build more complex HTTP request? The urllib.request....
How to use the "set-variable" Policy Statement to create custom variables for an Azure API service o...
Where to get the detailed description of the json_encode() Function in PHP? Here is the detailed des...
How to create a "Sign-up or Sign-in" user flow policy in my Azure AD B2C directory? If you want to b...
What is the "__init__()" class method? The "__init__()" class method is a special method that will b...