【发布时间】:2018-05-04 18:00:36
【问题描述】:
我知道这很简单,但我无法解决这个问题。请调查一下。
我有一个名为notification_updates 的表,它的数组是这样的:
Array
(
[0] => common\models\NotificationUpdates Object
(
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 1
[title] => This is the notification to inform you about this.
[status] => 1
[created_at] => 2017-11-20 08:29:21
)
)
[1] => common\models\NotificationUpdates Object
(
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 2
[title] => This is the notification to inform you about this cricket match
[status] => 1
[created_at] => 2017-11-20 06:24:09
)
)
[2] => common\models\NotificationUpdates Object
(
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 3
[title] => Inform you about this cricket match
[status] => 1
[created_at] => 2017-11-21 11:40:31
)
)
)
现在我还有 1 个表,其中第一个表的 primary_key (id) 在表 deleted_nofitication 中被称为 notification_id。
这个表也有这样的数组:
Array
(
[0] => common\models\DeletedNofitication Object
(
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[notification_id] => 1
)
)
[1] => common\models\DeletedNofitication Object
(
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[notification_id] => 2
)
)
)
现在我必须对照 user_id 检查天气 notification_updates 表是否有此值。如果它在那里,那么它不应该在JSON 下显示通知。
我已经在 PHP (YII2) 中完成了这样的操作 - 请检查一下
$notifications = NotificationUpdates::find()->where([])->all();
$outt = [];
foreach($notifications as $notification) {
$deleted_notification = DeletedNofitication::find()
->select('notification_id')
->where(['user_id'=>$user_id])
->all();
$outt[] = [
'id' => $notification->id,
'notification_title' => $notification->title
];
}
$out = [
'notification'=> $outt,
'success' => true,
'message' => 'All Notification Updates'
];
【问题讨论】:
标签: php arrays json arraylist yii2-advanced-app