severndigital Posted August 23, 2008 Share Posted August 23, 2008 ok so I want to run a function, but I only want to run it once. even if i call the page again. how do I run the function ONLY 1 time and then after re-calling the page reference the varibles values. Here is what i have function buryTreasure($h,$w){ //some math and data manipulation here $per = 10; $res = array(); for($i = 0; $i < $per; $i++){ $res[] = rand(0,100); } return $res; } now i want to run that function ONCE to get my result. But how do make it so that it I can use the result of the function? Thanks, C Link to comment https://forums.phpfreaks.com/topic/120980-referencing-info-from-an-if-statement/ Share on other sites More sharing options...
MasterACE14 Posted August 23, 2008 Share Posted August 23, 2008 once for 1 session? or once for all time? If its just once per session, use a session variable. <?php // check if its been called or not if($_SESSION['treasure'] == 0) { buryTreasure(1,1); $_SESSION['treasure'] = 1; } else { echo "Function has already been called this session!"; } or if its just once forever. Use a database to store 0 by default for the treasure. And then when its been called like above, update the database and set it to 1. Link to comment https://forums.phpfreaks.com/topic/120980-referencing-info-from-an-if-statement/#findComment-623675 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.