매우 간단하지만이를 해결할 수 없습니다. 이것을 들여다보십시오.PHP에서 array의 값을 비교하십시오 - 존재하지 않으면 json 배열에 추가하십시오
나는 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
)
)
)
는 지금은 첫 번째 테이블의
primary_key
(
id
가) 테이블
deleted_nofitication
에
notification_id
라고 foriegn 1 개 이상의 테이블이있다.
이 표는이 같은 배열이 있습니다
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
)
)
)
가 지금은 날씨 notification_updates 테이블이 user_id
에 대한이 값을 확인해야합니다. 알림이있는 경우 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'
];
deleted_nofitication ..에서 알림을 삭제했습니다. 이제 하나의 테이블 notification_updates에 모든 알림이 있습니다. 나는 거기에없는 알림을 사용자 ID와 함께 삭제하고 싶습니다.id = 1 인 경우 user_id = 1 인 deleted_nofitication에 있습니다. notification_updates 배열에서 그 통지를 얻지 않아야합니다. –
@SalmanRiyaz 당신이하려는 것을 봅니다. 편집을보십시오. – user2693053