Nie*_*app 2 php arrays laravel
$items1 = ['apple', 'tree', 'juice'];
$items2 = ['apple', 'tree'];
$items3 = ['apple'];
// loop
If ($items[i].containsOnly['apple'])
{
// do something..
}
Run Code Online (Sandbox Code Playgroud)
在上面的简化示例中,我想获取与给定项目匹配的数组。有没有类似于“ containsOnly”的方法?或最佳方法是什么?
//If the array has the only item present
if(in_array('apple',$item) && count($item)==1)
{
//Do Something
}
Run Code Online (Sandbox Code Playgroud)