I currently have a json array of objects and would like to fetch only the status fields. I need to verify if the status == 0
. If the status equals 0 then I would like for it to do something.
I would like to iterate through each object and grab the status value so that my the output depends on the value specified in each object. How can improve my code to iterate and grab the status column correctly for each object?
[
{
"user_id":"1",
"notification_id":"7",
"id":"7",
"product_id":"4233",
"message":"2",
"type":"2",
"created_at":"1493618633",
"status":"0"
},
{
"user_id":"1",
"notification_id":"8",
"id":"8",
"product_id":"4233",
"message":"4",
"type":"0",
"created_at":"1493618663",
"status":"0"
},
{
"user_id":"1",
"notification_id":"9",
"id":"9",
"product_id":"4232",
"message":"45",
"type":"1",
"created_at":"1493618784",
"status":"0"
}
]
model
public function getNotifications($timestamp, $user_id){
$sql = "SELECT * FROM storelte_user_notifications LEFT JOIN storelte_notifications ON storelte_user_notifications.notification_id = storelte_notifications.id WHERE created_at >= ? AND user_id = ? ORDER BY created_at";
$response = $this->db->query($sql, array($timestamp, $user_id));
return $response->result_array();
}
How I tried to fetch data in my json
$array = $this->notification->getNotifications($timestamp, $user_id);
if ($array > 0) {
if (empty(array_filter(array_column($array, 'status'))) == 0) {
echo 'unread';
}
}