douju1997
douju1997
2015-03-20 13:13

在PHP中使用in_array检查多个值

已采纳

I have a scenario as follows where I need to check value exists in array or not using in_array

$allRecordTypes =  array('new','newly','brandnew','branded');
$tempRecordTypes = array('new','newly');
$RecordType = in_array($tempRecordTypes,$allRecordTypes);

I'm sure that the above code is not correct, but I need to check whether the $tempRecordTypes need to be checked with $allRecordTypes.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douqin0676 douqin0676 6年前

    You need to use array_intersect() to see what values are in both arrays. in_array() checks to see if one value exists in an array so that won't work for you (unless you use a loop to iterate through your $tempRecordTypes array and compare it to the $allRecordTypes array).

    $RecordType = array_intersect($tempRecordTypes,$allRecordTypes);
    
    点赞 评论 复制链接分享

相关推荐