PHPize Online / SQLize Online

A A A
Share   Donate   Blog   Popular
Copy Format Clear
Copy
Copy Format Clear
<?php $arr = [1=>"A", "2" => "B", "6" => "Z"]; $un = ["G", "H", "I"]; //$out = [1=>"A", "2" => "B", 3 => "G", 4 => "H", 5 => "I" "6" => "Z"]; $order = 0; foreach($arr as $key=>$val) { while ((int)$key-$order > 1 && count($un)>0) { printf("order: %d, key, %d" . PHP_EOL, $order, $key ); $order++; $arr[$order] = array_shift($un); } $order++; } print_r($arr);
Show:  
Copy