0

I'm running a function that fires multiple loops (code below). Is there a way to run all of the loops simultaneously, then run the second function with the data created in the loops?

<?php

function simultaneousLoops() {
    for ($i = 1; $i < 100; $i++) { //create data };
    for ($i = 100; $i < 200; $i++) { //create data };
    for ($i = 200; $i < 300; $i++) { //create data };
};

function runAfterLoopsIsDone() {
     //do something with loop data
};
user1661677
  • 1,252
  • 5
  • 17
  • 32
  • There is no threading in PHP that I know of – Naftali Apr 05 '16 at 21:36
  • Those loops will run one by one, not simultaneously, so you can just call runAfterLoopsIsDone after the third loop. Do you mind sharing why you're doing this? – Eihwaz Apr 05 '16 at 21:36
  • What you're looking for is asynchronous code, afaik it's on the drawing board but not yet available (it is in Hacklang though). You could hack your way around it though, ie by using message queues and multiple workers, or probably a gazillion other ways – JimL Apr 05 '16 at 21:41

0 Answers0