Skip to content

Instantly share code, notes, and snippets.

@hungneox
Last active August 29, 2015 13:57
Show Gist options
  • Save hungneox/9683774 to your computer and use it in GitHub Desktop.
Save hungneox/9683774 to your computer and use it in GitHub Desktop.
<?php
$arr1 = array(0=>'0', 1=>'0', 2=>'0', 3=>'0', 4=>'0', 5=>'0', 6=>'0');
$arr2 = array(0=>'2', 3=>'5', 5=>'8');
$arr3 = array();
foreach($arr1 as $k1 => $v1){
foreach ($arr2 as $k2 => $v2) {
if($k1==$k2){
$arr3[$k1] = $v2;
} elseif($k1>=$k2){
$arr3[$k1] = $v2;
}
}
}
print_r($arr3);
@kcjpop
Copy link

kcjpop commented Mar 21, 2014

<?php

$a = [0, 0, 0, 0, 0, 0, 1];
$b = [0 => 2, 3 => 5, 5 => 8];
$c = [];

$n = max(count($a), count($b));
$i = 0;
while($n > 0 && $i < $n)
{
  if (isset($b[$i]))
  {
    $current = $b[$i];
  }

  $c[$i] = $current;

  $i++;
}

print_r($c);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment