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, ∼2475🔥, 0💬
Popular Posts:
Can You Add Values to an Array without Keys in PHP? Can You Add Values to an Array with a Key? The a...
How to build a test service operation to dump everything from the "context.Request" object in the re...
How To Convert a Character to an ASCII Value? If you want to convert characters to ASCII values, you...
What Is session_register() in PHP? session_register() is old function that registers global variable...
How to install .NET Framework in Visual Studio Community 2017? I have the Visual Studio Installer in...