I have the following variables:
$id = 1;
$data = [3, 17, 19, 21];
I need to create an array inserting the $id value before each value taken from $data, i.e.:
array (
0 => 1,
1 => 3,
2 => 1,
3 => 17,
4 => 1,
5 => 19,
6 => 1,
7 => 21,
)
How can I accomplish this without a loop?
What I have tried:
$id = 1;
$data = [3, 17, 19, 21];
foreach ($data as $val) {
$array[] = $id;
$array[] = $val;
}
It works, but I would like to find an alternative solution, like a built-in function.