fork(2) download
  1. <?php
  2.  
  3. $array = array(1 => 'foo', '4' => 'bar');
  4.  
  5. $firstIndexToEnsure = 1;
  6. $lastIndexToEnsure = 5;
  7. $defaults = array_fill($firstIndexToEnsure,
  8. $lastIndexToEnsure - $firstIndexToEnsure + 1,
  9. '');
  10. $array += $defaults;
  11.  
  12. print_r($array);
Success #stdin #stdout 0.03s 13064KB
stdin
Standard input is empty
stdout
Array
(
    [1] => foo
    [4] => bar
    [2] => 
    [3] => 
    [5] => 
)