See Anonymous function below, I do not want go to next for loop iteration until $Connected is 0
It did not work how it should be… what is the solution to fix this?
$Client = new Client();
for ($i = 1; $i <= 5; $i++) {
$result = $Client->Action(rand(1,1000));
if ($result->isSuccess()) {
$Connected = 1;
}
// Stay in the loop until 'HangupEvent' received
while ($Connected) {
$Client->EventListener(function (EventMessage $event) {
if ($event instanceof HangupEvent) {
// Received Hangup Event - let terminate this while loop ..
$Connected = 0;
}
});
// If $Connected = 0; then go to next `for` loop iteration
}
}
You need to pass the $Connected variable to your function with
use