title: PHP recursively apply a function to some array members, starting at a given index and walking through the array members till a given value
body: <p>Workin on PHP Version 5.6.33, I need to iterate through each member of a given array,  with the following restrictions:</p>
  
  <p>1) Need to iterate starting from a defined index,  not from the 0 index or the first member of the array.</p>
  
  <p>2) Need to iterate a given number of times,  but not through the whole array,  instead walk to array members till the given number of times is reached.</p>
  
  <p>Here is an example:</p>
  
  <pre><code>$arr = array(0,0,0,0,0,0);
  $repetitions = 10;
  $startingIndex = 3;
  function add($value, 1) {
     return $value + 1;
  }
  </code></pre>
  
  <p>walk through each array member, starting at index 3,  10 times,  adding 1 to each array member:</p>
  
  <pre><code>0 =&gt; 0
  1 =&gt; 0
  2 =&gt; 0
  3 =&gt; 0 + 1
  4 =&gt; 0 + 1
  5 =&gt; 0 + 1
  6 =&gt; 0 + 1
  </code></pre>
  
  <p>here I have walked 4 times,  6 are left:</p>
  
  <pre><code>0 =&gt; 0 + 1
  1 =&gt; 0 + 1
  2 =&gt; 0 + 1
  3 =&gt; 0 + 1 + 1
  4 =&gt; 0 + 1 + 1
  5 =&gt; 0 + 1 + 1
  6 =&gt; 0 + 1
  </code></pre>
  
  <p>so the final result is :</p>
  
  <pre><code>0 =&gt; 1
  1 =&gt; 1
  2 =&gt; 1
  3 =&gt; 2
  4 =&gt; 2
  5 =&gt; 2
  6 =&gt; 1
  </code></pre>
  
  <p>I obviously had made my work and tried <strong>array_map</strong>, <strong>array_walk</strong>, <strong>foreach</strong>, <strong>list</strong>, <strong>each</strong> (deprecated), but reading PHP manual,  I encounter that those functions aim to affect "every" array member.  Instead I need to affect some array members.</p>