How to pass PHP Variables by reference ? Last Updated : 20 Dec, 2018 Comments Improve Suggest changes Like Article 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 Comment More infoAdvertise with us H Harshit Saini Follow Improve Article Tags : Web Technologies PHP PHP Programs PHP-basics PHP-function +1 More Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like