【发布时间】:2019-08-08 15:28:30
【问题描述】:
$items1 = ['apple', 'tree', 'juice'];
$items2 = ['apple', 'tree'];
$items3 = ['apple'];
// loop
If ($items[i].containsOnly['apple'])
{
// do something..
}
在上面的简化示例中,我想获取与给定项目匹配的数组。有没有类似于“containsOnly”的方法?或者最好的方法是什么?
【问题讨论】:
-
您可以检查该项目是否在集合中以及集合的大小
-
只是补充一下,你应该改写你的问题,因为你说的是
collection,但你给了我们数组