|
|
Example:
<?php $a = 1; print("a before calling f( ) = " . $a . "\n"); f($a); print("a after calling f( ) = " . $a . "\n"); function f( $x ) # $x is passed by value { $x = 4444; } ?> |
Output:
a before calling f( ) = 1 a after calling f( ) = 1 |
How to run the program:
|
|
Example:
<?php $a = 1; print("a = " . $a . "\n"); f($a); print("a = " . $a . "\n"); function f (& $x ) # $x is passed by REFERENCE !!!! { $x = 4444; } ?> |
Output:
Before f(a): a = 1 After f(a): a = 4444 <--- Changed !!! |
How to run the program:
|
|
function f( & $x ) # How to pass array by reference { $x[0] = 4444; $x[1] = 4445; } |
|
$a = new myObject(); $a->x = 1; $a->y = 2; f( clone($a) ); // Pass a clone (= copy) of object to function php /home/cs377001/PHP/intro-PHP/pass-object2.php |