使用PHP,如何将订阅者与具有这两个阵列的用户匹配?
$订户
Array
(
[0] => stdClass Object
(
[meta_id] => 1
[email] => name@example.com
)
)
$用户
Array
(
[0] => stdClass Object
(
[ID] => 1
[user_email] => name@example.com
)
[1] => stdClass Object
(
[ID] => 2
[user_email] => name2@example.com
)
我以为会这样做......
<?php
foreach ( $users as $user ) {
if ( in_array( 'name@example.com', $subscribers ) ) {
echo 'Matched user';
}
}
答案 0 :(得分:3)
foreach ($users as $user) {
foreach ($subscribers as $subscriber) {
if ($user->user_email === $subscriber->email) {
echo 'Matched user';
break;
}
}
}