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.
Â
⇒Creating Your Own Functions in PHP
⇒⇒PHP Tutorials
2016-12-24, 1187👍, 0💬
Popular Posts:
How To Control Vertical Alignment? By default, text in all table cells are aligned to the top vertic...
How to use the "rewrite-uri" Policy Statement for an Azure API service operation? The "rewrite-uri" ...
Where to find tutorials on HTML language? I want to know how to learn HTML. Here is a large collecti...
Where to get the detailed description of the JSON.stringify() Function in JavaScript? Here is the de...
Where to find tutorials on Using Azure API Management Developer Portal? Here is a list of tutorials ...