I need to compare array of users with by database list of users. If database does not have data that is in array, I have to remove it. I have done this, but it prints like object, but i need to print it like array How it is:
{"user":"1"}{"user":"2"}{"user":"3"}{"user":"4"}
How it should be:
[{"user":"1"}{"user":"2"}{"user":"3"}{"user":"4"}]
I
$allUsers = [
"1",
"2",
"3",
"4",
"5",
];
foreach ($allUsers as $value) {
$users = [];
$sql = "select * from posts where user=:user order by id asc";
$data = $db->prepare($sql);
$data->execute(array(':user' => $value));
$allpost = $data->fetchAll();
$count = $data->rowCount();
if ($count !== 0) {
foreach($allpost as $user) {
$users = [
'user' => $user['user']
];
}
echo json_encode($users);
}
}