Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How Variables Are Passed Through Arguments
How Variables Are Passed Through Arguments? - PHP Script Tips - Creating Your Own Functions
✍: 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.
2007-04-24, 5105👍, 0💬
Popular Posts:
What will be printed as the result of the operation below: main() { int x=20,y=35; x=y++ + x++; y= +...
Which is the best place to store ConnectionString in Dot Net Projects? I am about to deploy my first...
How Is the Width a Parent Element Related to Child Elements? - CSS Tutorials - Understanding Multipl...
How can we format data inside DataGrid? Use the DataFormatString property.
Why does malloc(0) return valid memory address? What's the use? malloc(0) does not return a non-NULL...