-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"
3
  • Can you add a var_dump() of your variable so we can see how it's structured? Commented Jun 13, 2014 at 12:41
  • Also, please give your desired output... Commented Jun 13, 2014 at 12:41
  • 1
    please have a look stackoverflow.com/questions/1883421/… Commented Jun 13, 2014 at 12:48

1 Answer 1

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'];
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.