Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function by reference or value

Status
Not open for further replies.

rastkocvetkovic

Programmer
Aug 11, 2002
63
SI
Could somebody write a solution that would get the parameters by reference so that the code:

<?
$string = &quot;this is cool&quot;;

function by_reference($something) {
$something = &quot;this is new&quot;;
}

by_reference($string);

echo $string;

?>

Would output &quot;this is new&quot; and not &quot;this is cool&quot;.

I assume that all functions in PHP get parameters by value, how to transfort the $something to C++ style var $something. Thank you for answers!
 
I'll answer it myself. The difference is in &$something!
<?
$string = &quot;this is cool&quot;;

function by_reference(&$something) {
$something = &quot;this is new&quot;;
}

by_reference($string);

echo $string;

?>
This outputs &quot;this is new&quot;!
Hope this helps anyone else but me :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top