我想将诸如待定、发货或取消之类的查询字符串转换为数字状态。
$q = strtolower($keyword);
if($q == 'pen' or $q == 'pend' or $q == 'pending' ) {
$d = 1;
} elseif($q == 'shi' or $q == 'ship' or $q == 'shipped') {
$d = 2;
} elseif($q == 'can' or $q == 'cancel' ) {
$d = 3;
} else {
$d = 4;
}
$query->whereStatus($d);
当前查询工作正常但太多了or
。有可能以更短的方式做吗?
str_is(query, stringToSearch)
可能就足够了:
if (str_is('pen*', $q)) {
$d = 1;
}
否则,您可以从数组中解析它们:
$pendingArray = ['pen', 'pend', 'pending'];
if (in_array($q, $pendingArray)) {
$d = 1;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句