THIS IS MY ARRAY
Array
(
[0] => Array
(
[web_id] => 5
[attendance_data] => [{"id":"61","web_student_name":"Child One","attendance":false,"image":"img/reduser.png","$$hashKey":"object:361"},
{"id":"62","web_student_name":"Child Two","attendance":true,"image":"img/greenuser.png","$$hashKey":"object:362"}]
[class_id] => 20
[date] => 2019-03-11
[user] => A:5
[created_date] => 2019-03-11 03:54:50
[updated_date] => 2019-03-11 05:53:50
)
[1] => Array
(
[web_id] => 6
[attendance_data] => [{"id":"61","web_student_name":"Child One","attendance":false,"image":"img\/reduser.png","$$hashKey":"object:361"}]
[class_id] => 20
[date] => 2019-03-08
[user] => A:5
[created_date] => 2019-03-11 05:53:27
[updated_date] => 2019-03-11 05:53:27
)
[2] => Array
(
[web_id] => 15
[attendance_data] => [{"id":"61","web_student_name":"Child One","attendance":true,"image":"img/greenuser.png","$$hashKey":"object:198"},{"id":"82","web_student_name":"Child Three","attendance":false,"image":"img/reduser.png","$$hashKey":"object:199"},{"id":"62","web_student_name":"Child Two","attendance":true,"image":"img/greenuser.png","$$hashKey":"object:200"}]
[class_id] => 20
[date] => 2019-03-04
[user] => A:5
[created_date] => 2019-03-14 01:42:40
[updated_date] => 2019-03-14 01:42:40
)
)
I want to unset the JSON item of attendance_data where id is not equal to 61. Only show the JSON item list of attendance_data where id = 61 only. I tried for not able to unset JSON item. Please provide the solution.
Thanks in advance.
WHAT I TRIED
foreach($data as $key => $value) {
$json_arr = json_decode($data[0]['attendance_data'], true);
$arr_index = array();
foreach ($json_arr as $key1 => $value1) {
if ($value1['id'] != $childid) {
$arr_index[] = $key1;
}
}
foreach ($arr_index as $i) {
unset($json_arr[$i]);
}
$json_arr = array_values($json_arr);
$json_arr_en = json_encode($json_arr);
$data[$key1]['attendance_data'] = $json_arr_en;
}
foreach($data as $key => $value) { $json_arr = json_decode($data[0]['attendance_data'], true); $arr_index = array(); foreach ($json_arr as $key1 => $value1) { if ($value1['id'] != $childid) { $arr_index[] = $key1; } } foreach ($arr_index as $i) { unset($json_arr[$i]); } $json_arr = array_values($json_arr); $json_arr_en = json_encode($json_arr); $data[$key1]['attendance_data'] = $json_arr_en; }@RiggsFolly