PHP question: what is the role and the name(PHP wise) of the '&' symbol in this code ?

Xub Yubzub

New member
<?php
function reverseIt(&$strString) {
$strString = strrev($strString);
}
$strName = "Simon";
echo "<p>$strName ";
reverseIt($strName);
echo "reversed is $strName</p>";
?>
it works with the '&' but without it it just says 'Simon reversed is Simon' instead of 'Simon reversed is moniS'.
It's from the book 'Dynamic Web Application Development using PHP and MySQL' by Simon Stobart and David Parsons on pg.386 if that's any help.
 
Basically it changes the value of the string outside of the function. Usually this function would reverse $strString within the function, but outside the function, the value is unchanged.

You can also use $GLOBALS['strString'] to change the 'global' value of the variable outside of the function.

See this: http://www.whypad.com/posts/php-what-is-the-ampersand-preceding-variables/193/
 
Back
Top