0

私はいくつかの PHP プログラミングを行っていますが、質問があります: PHP スクリプトが最初に実行されたときに、最初に実行されたときにのみ PHP 関数をロードするにはどうすればよいですか?

ありがとう

4

4 に答える 4

0

またはプレーンブール値を使用してください...

$bFirstRun = true;

if( $bFirstRun ) {
    run_me();
    $bFirstRun = false;
}
于 2012-05-07T23:17:05.377 に答える
0

というPHP関数があります。function_exists

この関数内に独自の関数を定義すると、これが存在するかどうかを確認できます。

if (!function_exists('myfunction')) {
  function myfunction() {
    // do something in the function
  }
  // call my function or do anything else that you like, from here on the function exists and thus this code will only run once.
}

function_exists の詳細については、http ://www.php.net/function_exists をご覧ください。

于 2012-05-07T23:23:55.293 に答える