Alan Alan - 2 months ago 7
PHP Question

How to merge the keys from two different arrays in PHP

So I have two arrays. My main one is stored in a variable called

$topVideos
looks like this:

["rows"] => array(10) {
[0] => array(2) {
[0] => string(11) "GARuSV"
[1] => float(2003)
}
[1] => array(2) {
[0] => string(11) "rDnbeSrk"
[1] => float(1119)
}
[2] => array(2) {
[0] => string(11) "0ykEqaUI"
[1] => float(1015)
}


And the second one is stored in a variable called
$titles
and looks like this:

array(10) {
[0] => string(25) "Serve Heroes"
[1] => string(38) "Rover Sailing Adventure!!"
[2] => string(54) "BNI Presentation"


What I have to do is merge the second one's every key into the first one's, so it can look like this:

["rows"] => array(10) {
[0] => array(2) {
[0] => string(11) "GARuSV"
[1] => float(2003)
[3] => string(25) "Serve Heroes"
}
[1] => array(2) {
[0] => string(11) "rDnbeSrk"
[1] => float(1119)
[3] => string(25) "Rover Sailing Adventure!!"
}
[2] => array(2) {
[0] => string(11) "0ykEqaUI"
[1] => float(1015)
[3] => string(25) "BNI Presentation"
}


How can I accomplish this? Any help is welcomed! Thank you for your time

Answer
foreach($titles as $key => $title){
    $topVideos["rows"][$key][] = $title;
}