0

The $value prints correctly. The number(s) are correct for $value so I think that part is eliminated.

If I manually enter the actual numbers in ($value)->price like (10079)->price, the function works fine and the last line print_r ($price) prints the number it supposed to.

For some reason $value is not working in the context of $xml_price = $fetch_app->products($value)->price; as the function returns nil for $price

foreach ($_SESSION['queueList'] as $value){
            //this prints the correct item(s) in 'queueList'
            print_r ($value);
            //this gets the node with the price info
            $xml_price = $fetch_app->products($value)->price;
            //this converts the simpleXML node to a string
            $price = ((string) $xml_price);
            //session var accumulates the item prices in cart
            $_SESSION['totalPrice'] += $price;
            print_r ($price);

        }

So why is the $value variable not working, but an actual number does, even though I have printed the $value and it shows the correct number? The number is a float by the way, not sure if that matters.

7
  • have you tried explicitly casting $value as an (int). It may be treating it as a string? Commented Mar 15, 2013 at 23:02
  • Also use var_dump() to see the actual variable type and content (extra fillers e.g.) Commented Mar 15, 2013 at 23:03
  • 1
    use var_dump() for debugging, not print_r. It shows more info about the variable, namely type and length, which might be the problem. Commented Mar 15, 2013 at 23:03
  • @pburgess yes I tried $price = ((int) $xml_price); same results Commented Mar 15, 2013 at 23:06
  • @michi the FetchApp API PHP library: fetchapp.com Commented Mar 15, 2013 at 23:07

1 Answer 1

2

Judging by the additional information from the comments, the following should work:

$xml_price = $fetch_app->products((int)$value)->price;

It looks like this fetchapp API is strongly typed, which is untypical for PHP but still technically possible to a certain extent. At least it treats string parameters different from integer parameters.

Sign up to request clarification or add additional context in comments.

1 Comment

this solved it for me foreach ($_SESSION['queueList'] as $value){ //this gets the node with the price info $xml_price = $fetch_app->products($value)->price; // convert the simpleXML node to a string $price = ((string) $xml_price) * 100; //session var accumulates the item prices in cart $_SESSION['totalPrice'] += $price; }

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.