title: Expand array of numbers and hyphenated number ranges to array of integers
body: <p>I'm trying to normalize/expand/hydrate/translate a string of numbers as well as hyphen-separated numbers (as range expressions) so that it becomes an array of integer values.</p>
  <p>Sample input:</p>
  <pre><code>$array = [&quot;1&quot;,&quot;2&quot;,&quot;5-10&quot;,&quot;15-20&quot;];
  </code></pre>
  <p>should become :</p>
  <pre><code>$array = [1,2,5,6,7,8,9,10,15,16,17,18,19,20];
  </code></pre>
  <p>The algorithm I'm working on is:</p>
  <pre><code>//get the array values with a range in it :
  $rangeArray = preg_grep('[-]',$array);
  </code></pre>
  <p>This will contain <code>[&quot;5-10&quot;, &quot;16-20&quot;];</code> Then :</p>
  <pre><code>foreach($rangeArray as $index=&gt;$value){
      $rangeVal = explode('-',$value);
      $convertedArray = range($rangeVal[0],$rangeVal[1]);
  }
  </code></pre>
  <p>The converted array will now contain <strong>[&quot;5&quot;,&quot;6&quot;,&quot;7&quot;,&quot;8&quot;,&quot;9&quot;,&quot;10&quot;]</strong>;</p>
  <p>The problem I now face is that, how do I pop out the value &quot;5-10&quot; in the original array, and insert the values in the <strong>$convertedArray</strong>, so that I will have the value:</p>
  <pre><code>$array = [&quot;1&quot;,&quot;2&quot;,**&quot;5&quot;,&quot;6&quot;,&quot;7&quot;,&quot;8&quot;,&quot;9&quot;,&quot;10&quot;**,&quot;16-20&quot;];
  </code></pre>
  <p>How do I insert one or more values in place of the range string? Or is there a cleaner way to convert an array of both numbers and range values to array of properly sequenced numbers?</p>