如何从$sku
变量中删除一些值?它会从DB返回2110
,1630
,4565
等。
代码:
$products = SProductVariantsQuery::create()->find()->toArray();
foreach ($products as $variant) {
$sku = $variant['Number'];
}
var_dump($ sku)返回:
string(4) "2250" string(4) "2251" string(3) "428" string(3) "427" string(4) "2800" string(4) "2804"
答案 0 :(得分:1)
在执行foreach之前创建一个包含要排除的值的数组,然后检查该值是否在那里:
// Exclude prod. no 427 and 2800
$exclude = array('427', '2800');
foreach ($products as $variant) {
// Only set $sku if the Number is not in the exclude array
if (!in_array($variant['Number'], $exclude)) {
$sku = $variant['Number'];
}
}