Storing and getting variables between php functions?

From: Date: Fri, 09 Feb 2001 23:22:06 +0000
Subject: Storing and getting variables between php functions?
Groups: php.general 
Request: Send a blank email to php-general+get-39024@lists.php.net to get a copy of this message
HI is it possible to do what i have shown with the 3 php files under? I want that a variable stored in a another php file like this, and then i want to get the stored variable from a 3rd php file. How can i do this, i have tried it but it does not work. When i get the variable in the 3rd php file it is empty. It seems like i cant store variable outside the function, and then use it in other functions in the same php file. Is that true! In JAVA and C++ this was a piece of cake... Thanks in advance from a frustrated student from Norway. -------------- php file called setget.php <?php $temp;// I want to use this as a storing variable until i need this value by calling the getvariable function function setvariable($subject)// storing the variable temp { $temp=$subject; } function getvariable()//getting the variable temp with its stored value which was set by function setvariable { return $temp; } ?> ---------------------------------------------- php file called set.php <?php require("setget.php"); $setvariable="subject";//seting the variable setvariable($setvariable);//storing a value to the variable in setget.php ?> ------------------------------------------------------- php file called get.php <?php require("setget.php"); $data=getvariable(); print "$data";//gettin what i stored in set.php by calling the function in setget.php, but it comes out empty ?> ----------------------------------------------------------

« previous php.general (#39024) next »