从数组中排除多个值 [英] Excluding multiple values from the array
问题描述
我有以下代码
'delete' => function($url, $model) {
$url = Url::to(['category/delete/'.$model->info_category_id]);
return ($model->info_category_id !== 11)?Html::a('<i class="icon-trash"></i>', $url, ['class'=>'black-txt tips del-confirm-subitems']):'';
},
关于在后端创建特定类别的删除功能.如您在第三行中看到的,它从删除功能中排除了类别ID号11.除了类别ID编号11,我还想从数据库中添加类别ID编号15,但是当我按以下方式插入15时,它会导致错误:($model->info_category_id !== 11, 15)
.
which are about creating the delete function of a certain category in the backend. As you see in the third line it excludes the category id number 11 from delete function. Beside category id number 11 I would also like to add category id number 15 from the database, however it leads to error when I insert 15 as following: ($model->info_category_id !== 11, 15)
.
如果能帮助我在代码中正确插入category_id数字15,我们将不胜感激.
I would appreciate if you could help me to insert category_id number 15 correctly to the codes.
谢谢.
推荐答案
尝试以下操作:
return (!in_array($model->info_category_id,[11,15]))?Html::a('<i class="icon-trash"></i>', $url, ['class'=>'black-txt tips del-confirm-subitems']):'';
您的操作方式对于PHP来说是错误的语法.上面的示例使用in_array
函数来确定$model->info_category_id
的值是否与提供的数组内的任何值匹配.或者您可以尝试这样:
the way you are doing it is incorrect syntax for PHP. The above example uses in_array
function to determine whether the value of $model->info_category_id
matches any value inside the provided array. Or you can try like this:
return ($model->info_category_id !== 11 && $model->info_category_id !== 15)?Html::a('<i class="icon-trash"></i>', $url, ['class'=>'black-txt tips del-confirm-subitems']):'';
它只是单独检查值.
这篇关于从数组中排除多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!