$items1 = ['apple', 'tree', 'juice'];
$items2 = ['apple', 'tree'];
$items3 = ['apple'];
// loop
If ($items[i].containsOnly['apple'])
{
// do something..
}
在上面的简化示例中,我想获取与给定项目匹配的数组。是否有类似于“containsOnly”的可用方法?或者最好的方法是什么?
最佳答案
//If the array has the only item present
if(in_array('apple',$item) && count($item)==1)
{
//Do Something
}
关于php - 如何检查项目数组是否仅包含此项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55218373/