The number of items in both arrays $newResponse
& $key
will always be same.For each item of the $newResponse
, i wanted to add items of $key
to $newResponse
in the same order they exists in $key
array as mentioned in the Expected result.How can i achieve that?
dump($newResponse);
is an array like below,which am getting as the result of a foreach
loop.
array:4 [
0 => array:6 [
"courseId" => 18
"courseDisplayName" => "qqq"
]
1 => array:6 [
"courseId" => 1
"courseDisplayName" => "ips"
]
2 => array:6 [
"courseId" => 18
"courseDisplayName" => "qqq"
]
3 => array:6 [
"courseId" => 1
"courseDisplayName" => "ips"
]
]
dump($key);
is an array like below, which is the result of another foreach
loop.
array:4[
0=>[
"totalPoints" => 2
"percent" => 1.0
"id" => 2
]
1=> [
"totalPoints" => 10
"percent" => 2
"id" => 3
]
2=> [
"totalPoints" => 4
"percent" => 0.0
"id" => 6
]
3=> [
"totalPoints" => 4
"percent" => 0.0
"id" => 5
]
]
Expected result:
[
[
"courseId" => 18
"courseDisplayName" => "qqq"
"totalPoints" => 2
"percent" => 1.0
"id" => 2
]
[
"courseId" => 1
"courseDisplayName" => "ips"
"totalPoints" => 10
"percent" => 2
"id" => 3
]
[
"courseId" => 18
"courseDisplayName" => "qqq"
"totalPoints" => 4
"percent" => 0.0
"id" => 6
]
[
"courseId" => 1
"courseDisplayName" => "ips"
"totalPoints" => 4
"percent" => 0.0
"id" => 5
]
]