如果评论者的电子邮件匹配,我想根据数组定义的值打印作者角色。
这里定义了配置数组。
// Get Comment
$comment = get_comment();
// Get Commenters email
$match_email = $comment->comment_author_email;
// Config arrays
$config = [
'verified_email' => [
'[email protected]' => [
'role' => 'Seo Expert',
],
'[email protected]' => [
'role' => 'Manager',
]
]
];
这是foreach循环。
foreach ($config as $group => $users) {
foreach ($users as $author => $email) {
if (($email === $match_email) && have_comments()) {
echo $email['role'];
break;
}
}
}
如果电子邮件 ID 匹配,如何从配置数组值打印作者角色。
根据目前的情况,我可以看到 if 里面的
$email
应该替换为 $author
:
if ($author === $match_email && have_comments()) {
echo $email['role'];
break;
}