hello,
here i have a application that, i need to call the function only once, during the execution of the program,
please help me
Regards
Murali
how can i call function only once in the page
Moderator: General Moderators
-
B.Murali Krishna
- Forum Commoner
- Posts: 28
- Joined: Fri May 12, 2006 2:05 am
- Location: Hyderabad,India
- Contact:
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Put a static variable in it and set it true.
Code: Select all
function echoOnce($word)
{
static $has_run = null;
if ($has_run) return;
echo $word;
$has_run = 1;
}
echoOnce("Foo");
echoOnce("Bar");Re: how can i call function only once in the page
I would suggest your reconsider the workflow. While it is possible you have such weird situation it is more likely you don't need this behaviour at all.B.Murali Krishna wrote:hello,
here i have a application that, i need to call the function only once, during the execution of the program,
please help me
Regards
Murali
Fix design up front to have less trouble/mess later.