I have an array like this.
$array = [
0 =>[
"name" => "John",
"age" => "20",
"class" => "first"
],
1 => [
"name" => "Doe",
"age" => "22",
"class" => "second"
],
2 => [
"name" => "Template",
"age" => "30",
"class" => "third"
],
];
foreach ($array as $arr) {
if ($arr["name"] == "Template") {
$arr["result"] = ["maths" => "60", "English" => "20"];
array_push($arr,$arr["result"]);
}
}
I have tried several things like using array_push($arr,$arr["result"]) but that still returns the array.
How can i loop through it to return something like this.
2 => [
"name" => "Template",
"age" => "30",
"class" => "third",
"result"=> ["maths" => "60", "English" => "20"],
],