How to pass PHP Variables by reference ? Last Updated : 20 Dec, 2018 Comments Improve Suggest changes 2 Likes Like Report By default, PHP variables are passed by value as the function arguments in PHP. When variables in PHP is passed by value, the scope of the variable defined at function level bound within the scope of function. Changing either of the variables doesn't have any effect on either of the variables. Example: php <?php // Function used for assigning new // value to $string variable and // printing it function print_string( $string ) { $string = "Function geeksforgeeks"."\n"; // Print $string variable print($string); } // Driver code $string = "Global geeksforgeeks"."\n"; print_string($string); print($string); ?> Output: Function geeksforgeeks Global geeksforgeeks Pass by reference: When variables are passed by reference, use & (ampersand) symbol need to be added before variable argument. For example: function( &$x ). Scope of both global and function variable becomes global as both variables are defined by same reference. Therefore, whenever global variable is change, variable inside function also gets changed and vice-versa is applicable. Example: php <?php // Function used for assigning new value to // $string variable and printing it function print_string( &$string ) { $string = "Function geeksforgeeks \n"; // Print $string variable print( $string ); } // Driver code $string = "Global geeksforgeeks \n"; print_string( $string ); print( $string ); ?> Output: Function geeksforgeeks Function geeksforgeeks Create Quiz Comment H Harshit Saini Follow 2 Improve H Harshit Saini Follow 2 Improve Article Tags : Web Technologies PHP PHP Programs PHP-basics PHP-function +1 More Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like