<?php $a = [ [ 'position' => 0, 'color' => 'violet' ], [ 'position' => 2, 'color' => 'red' ], [ 'position' => 5, 'color' => 'green' ], ]; $b = [ [ 'color' => 'yellow' ], [ 'color' => 'orange' ], [ 'color' => 'pink' ], [ 'color' => 'blue' ], ]; $pos = array_column($a, "color", "position"); $count = count($pos) + count($b); $j = 0; for($i=0; $i<$count-1; $i++){ if(!isset($pos[$i])){ $pos[$i] = $b[$j]; $j++; }else{ $pos[$i] = [$pos[$i]]; } } ksort($pos); var_dump($pos);
You have javascript disabled. You will not be able to edit any code.