Skip to content
Advertisement

Get values from SimpleXMLElement Object for php array

I need help with this issue, it seems I can’t get targetCurrency out of the SimpleXMLElement Object

JavaScript

This outputs:

JavaScript

[curr_code] should output ‘EUR’.

How can I fix it?

Advertisement

Answer

You are using the same variable name for two different things:

JavaScript

If you were running with display_errors switched on or checking your logs, you would have seen a message like this:

Notice: Trying to get property ‘targetCurrency’ of non-object

Or in PHP 8, this:

Warning: Attempt to read property “targetCurrency” on string


The fix is simply to name your variables more carefully:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement