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 To Pass Variables By References
How To Pass Variables By References? - PHP Script Tips - Creating Your Own Functions
✍: FYIcenter.com
You can pass a variable by reference to a function by taking the reference of the original variable, and passing that reference as the calling argument. Here is a PHP script on how to use pass variables by references:
<?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: JSP, PHP
As you can see, the function modified the original variable.
Note that call-time pass-by-reference has been deprecated. You need to define arguments as references. See next tip for details.
2007-04-24, 4825👍, 0💬
Popular Posts:
How can I implement a variable field width with printf? That is, instead of something like %8d, I wa...
Can you explain the fundamentals of “GetGlobalResourceObject ”and “GetLocalResourceObject” function...
What invokes a thread's run() method? After a thread is started, via its start() method of the Threa...
How To Define a Data Source Name (DSN) in ODBC Manager? - Oracle DBA FAQ - ODBC Drivers, DSN Configu...
What are the five levels in CMMI? There are five levels of the CMM. According to the SEI, Level 1 – ...