-1

How can I remove some values from $sku variable? It returns 2110, 1630, 4565, etc. from DB.

Code:

$products = SProductVariantsQuery::create()->find()->toArray();

foreach ($products as $variant) {
$sku = $variant['Number'];
}

var_dump($sku) return this:

string(4) "2250" string(4) "2251" string(3) "428" string(3) "427" string(4) "2800" string(4) "2804"
TarasH
  • 55
  • 10

1 Answers1

1

Create an array with values you want to exclude before you do the foreach and then check if the value is in there:

// 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'];
    }
}
Oldskool
  • 34,211
  • 7
  • 53
  • 66