Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
$arr = [1=>"A", 2 => "B", 6 => "Z"];
$un = ["G", "H", "I"];
$length = count($arr) + count($un);
for ($i = 1; $i <= $length; $i++) {
if (!array_key_exists($i, $arr)) $arr[$i] = array_shift($un);
}
ksort($arr);
$res = array();
$res[] = $arr;
echo json_encode($res);