$classType
array i am storing the class wise type like class 1 having type A & class 2 having type is A & class 3 having type is B
$clollege['studentDetails']
array i want to push type from $classType
array based on class what is the type
$clollege['studentDetails']
grade and $classType
class both are same.
Expected Output
Array
(
[0] => Array
(
[grade] => 2
[hobbies] => Array
(
[0] => A
[1] => B
)
[type] => A
)
[1] => Array
(
[grade] => 2
[hobbies] => Array
(
[0] => A
)
[type] => A
)
[2] => Array
(
[grade] => 3
[hobbies] => Array
(
[0] => C
)
[type] => A
)
I have tried but not working my expected answer,kindly anyone updaye my answer, i have posted my code in below section. i know this is simple question , if anyone post your so that i can learn from here How to push
My Code
<?php
$classType = [
["class" => "1", "type" => "A"],
["class" => "2", "type" => "A"],
["class" => "3", "type" => "B"]
];
$clollege['studentDetails'] = [
["grade" => "2", "hobbies" => ["A" , "B"] ],
["grade" => "2", "hobbies" => ["A" ] ],
["grade" => "3", "hobbies" => [ "C" ] ]
];
foreach ($classType as $item) {
$clollege['studentDetails'][$item['class']]['type'] = $item['type'];
}
echo "<pre>";
print_r($clollege['studentDetails']);exit;
?>
Update code section
$studentList['studentDetails'] = [
[ "group" => ["id" => 1 , "grade" => "2"] ],
[ "group" => ["id" => 2 , "grade" => "2", ] ],
[ "group" => [ "id" => 3, "grade" => "3"] ]
];