$message
各受信者 (受信者は)をループする必要がありarray
、何か問題が発生した場合はunset
、対応する受信者:
$recipients = &$message->getRecipients(); // array
// Do this now as arrays is going to be altered in the loop
$count = count($recipients);
for($i = 0; $i <= $count; $i++):
$response = $messageManager->send($recipients[$i], $content);
// If not 200 OK remove the recipient from the message
if($response->getStatusCode !== 200) unset($recipients[$i]);
endfor;
しかし、「変数のみを参照によって割り当てることができる」ため、PHP ではこれを行うことができません。配列を再割り当てする以外に、私にできることはありますか:
$recipients = $message->getRecipients();
// Loop
$message->setRecipients($recipients);
EDIT : foreach を使用して現在の要素を参照渡しすることはできません:
$recipients = array('a', 'b', 'c');
foreach($recipients as &$recipient)
unset($recipient);
echo count($recipients); // 3