私は関数を持っており、完了したら出力ログを電子メールに集める必要があります。それは次のようになります。some text || some more text || last line of text
:今内部関数から親変数への文字列の追加
function blabla() {
$emailMessage = "some text";
$emailMessage .= "some more text";
function foo() {
for ($x = 1; $x <= 20; $x++) {
$emailMessage .= 'Call #' . $x;
// then doing an API call
return $response;
}
}
$res = foo();
$emailMessage .= "last line of text";
}
$emailMessage
は次のようになります。内部関数のテキストは付加されません。私はグローバル変数を使用some text || some more text || call #1 || call #2 ||... || last line of text
------ ------ EDIT @kamal PALへ
ありがとう:どのように私はそれがこのように見えるように取得することができます
。結果は次のようになります。
function blabla() {
global $emailMessage;
$emailMessage = "some text";
$emailMessage .= "some more text";
function foo() {
global $emailMessage;
for ($x = 1; $x <= 20; $x++) {
$emailMessage .= 'Call #' . $x;
// then doing an API call
return $response;
}
}
$res = foo();
$emailMessage .= "last line of text";
}
なぜ「内部機能」を使用しますか? – zoubida13