I have two arrays, $array1 and $array2, now I want to take the values from $array2 and put each element at the start of each subArray from $array1
First array:
$array1 = Array (
[0] => Array (
[0] => 2
[1] => 6
[2] => 15
[3] => 6
)
[1] => Array (
[0] => 5
[1] => 8
[2] => 6
[3] => 12
)
[2] => Array (
[0] => 2
[1] => 5
[2] => 5
[3] => 5
)
)
Second array:
$array2 = Array (
[0] => Outlook
[1] => Temp
[2] => Humidity
)
Expected output (modified/new values bold):
$array1 = Array (
[0] => Array (
[0] => 'Outlook'
[1] => 2
[2] => 6
[3] => 15
[4] => 6
)
[1] => Array (
[0] => 'Temp'
[1] => 5
[2] => 8
[3] => 6
[4] => 12
)
[2] => Array (
[0] => 'Humidity'
[1] => 2
[2] => 5
[3] => 5
[4] => 5
)
)
array_unshift()2) Or you look atarray_map()and atarray_unshift(). Read the pages carefully, look at the examples, try to write some code, and if you get stuck post the attempt here. And we will help you to finish it :)