How to write a function that can be called only once in PHP

1 Answer

0 votes
function once($n) {
    static $called = false;
    if (!$called) {
        $called = true;
        echo $n;
    }
}

once(23);
once(87);


/*
run:

23
 
*/

 



answered Mar 1, 2019 by avibootz
...