3v4l.org

run code in 300+ PHP versions simultaneously
<?php $lists = [ ['A', 'B', 'C', 'D', 'E'], ['A', 'B', 'C', 'D'], ['A', 'B', 'C', 'D', 'E', 'F'], ]; foreach ($lists as &$row) { $newRow = []; foreach ($row as $i => $v) { $newRow['Key' . $i + 1] = $v; } $row = $newRow; } var_export($lists);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
array ( 0 => array ( 'Key1' => 'A', 'Key2' => 'B', 'Key3' => 'C', 'Key4' => 'D', 'Key5' => 'E', ), 1 => array ( 'Key1' => 'A', 'Key2' => 'B', 'Key3' => 'C', 'Key4' => 'D', ), 2 => array ( 'Key1' => 'A', 'Key2' => 'B', 'Key3' => 'C', 'Key4' => 'D', 'Key5' => 'E', 'Key6' => 'F', ), )

preferences:
76.5 ms | 407 KiB | 5 Q