I am learning PHP. I am using for loop like below in one of my php function.
$numbers = $data["data"];
for ($i = 0;$i < count($numbers);$i++) {
$w->send($numbers[$i]);
}
I want check that if its last number, I need sleep some second and want call one other function. I do not know how can I do it. can anyone please suggest me what should I do for it? Thanks
$numbers = $data["data"];
for ($i = 0,$c=count($numbers);$i < $c;$i++) {
$w->send($numbers[$i]);
if($i==$c-1){
sleep(60);
//call your function here;
}
}
You can simply do, what you want to do, after the loop:
$numbers = $data["data"];
foreach ($numbers as $number) {
$w->send($number);
}
$w->send($otherNumber);
sleep($forSomeSeconds);
I also changed the for
loop to a foreach
loop after the comment made by Elementary.