title: How to make an asynchronous self-calling loop non-recursive
body: <p>I'm writing a function in PHP that loops through an array, and then performs an asynchronous call on it (using a Promise).</p>
  
  <p>The problem is that, the only way I can make this loop happen, is by letting a function call itself asynchronously. I run into the 100-nested functions problem really quick, and I would basically like to change it to not recur.</p>
  
  <pre><code>function myloop($data, $index = 0) {
  
      if (!isset($data[$index])) {
          return;
      }
  
      $currentItem = $data[$index];
      $currentItem()-&gt;then(function() use ($data, $index) {
         myloop($data, $index + 1);   
      });
  
  }
  </code></pre>
  
  <p>For those that want to answer this from a practical perspective (e.g.: rewrite to not be asynchronous), I'm experimenting with functional and asynchronous patterns and I want to know if it is possible to do this with PHP.</p>