<?php
$keys = ['k1', 'k2', 'k3', 'k4'];
$res1 = [];
// Foreach
foreach ($keys as $key) {
$res1[$key] = [
'start' => 1,
'end' => 2,
];
}
// array_fill_keys
$res2 = array_fill_keys($keys, [
'start' => 1,
'end' => 2,
]);
//array_reduce
$res3 = array_reduce($keys, function($acc, $key) {
$acc[$key] = [
'start' => 1,
'end' => 2,
];
return $acc;
}, []);
print_r($res1);
print_r($res2);
print_r($res3);