How can I pass PHP variables by reference?

PHP

Example :  
// Function used to assign a new
// $string variable value and
// print function print_string ( $string ) { $string = " Function engineerforengineer " . "" ; // Print the $string variable print ( $string ); }  
// Driver code $string = "Global engineerforengineer" . "" ; print_string ( $string ); print ( $string ); ?>
Exit:
Function engineerforengineer Global engineerforengineer 
Pass by reference:When variables are passed by reference, the & amp; character must be added before using the variable argument. (ampersand). For example: function (& amp; $x). The scope of both the global and the functional variable becomes global because both variables are defined by the same reference. Therefore, whenever a global variable changes, the variable inside the function also changes and vice versa.Example :  
// Function used to assign a new values ​​
// $string variable and printing it function print_string (& amp; $string ) { $string = "Function engineerforengineer" ; // Print the $string variable print ( $string ); }  
// Driver code $string = "Global engineerforengineer" ; print_string ( $string ); print ( $string ); ?>
Exit:
Function engineerforengineer Function engineerforengineer 




Get Solution for free from DataCamp guru