0

I've got a slight problem with figuring out the logic for the following problem.

I have a webshop which sells ankle braces. Left and Right. For each brace a scan of the corresponding ankle is neccesary. So, for example, I cannot buy a left brace if I only have a scan of the right ankle. I have two arrays. First array contains the scan data and the second is the web cart containing all the products. But I can't wrap my head around the logic:

return false if a product is in the cart while its scan is not available.

I could just do a bunch of if statements but i'm certain that there is a logical and cleaner way.

Here are the arrays

Array
(
    [left] => Array
        (
            [0] => data
            [1] => data2
            [2] => data3
        )

    [right] => Array
        (
            [0] => data
            [1] => data2
            [2] => data3
        )

)

Array
(
    [product_id1] => Array
        (
            [var] => val
            [side] => left
        )

    [product_id2] => Array
        (
            [var] => val
            [side] => right
        )

)

1 Answer 1

1

Something like this might help:

function check($product) {
    if ($product['side'] == 'left' && !isset($scans['left']) || 
        $product['side'] == 'right' && !isset($scans['right'])) {
          return false;
        }
    return true;
}

foreach ($cart as $product) {
  check($product);
}
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.