jeudi 7 avril 2016

Isset() returning false when it should be true - Symfony PHP

I am a new developer working at a company on a website. I am using isset() to check if something is set within a variable that I know has a value, but it is always returning false. Here is the code:

            $prices_with_source = $user_company->getBranchApiImplementation()->getApiClass($controller,$apiDisabled)->getProductPrices($em, $partnership, array( array('product' => $product , 'quantity' => 1) ));
            $prices_with_source = is_array($prices_with_source) ? reset($prices_with_source) : $prices_with_source;

            if (isset($prices_with_source['discountedPrice']) && $prices_with_source['discountedPrice'] > 0) {
                $price = $prices_with_source['discountedPrice'];
            }



            if (isset($prices_with_source['suggestedPrice'])) {
                $price = $prices_with_source['suggestedPrice'];
            }

It is supposed to enter the if statements because I know that the $price_with_sources has values. I dont know why it is not working. I used var_dump to check the value of the $prices_with_sources before the if statements and this is the output:

array(1) {
    [1]=> array(3) {
        ["discountedPrice"]=> string(4) "5.99"
        ["suggestedPrice"]=> string(4) "5.99"
        ["source"]=> int(0)
    }
}

If anyone has any helpful information it would be greatly appreciated, thanks!

Aucun commentaire:

Enregistrer un commentaire