0

prob an easy fix, but I'm stuck.

So print_r($data) =

stdClass Object (
    [code] => 200000
    [data] => stdClass Object (
        [accountEquity] => 111
        [unrealisedPNL] => 111
        [marginBalance] => 111
        [positionMargin] => 111
        [orderMargin] => 0
        [frozenFunds] => 0
        [availableBalance] => 111
        [currency] => xxx
    )
)

And echo $data->code outputs '20000'

But I can not get the other 'variables' to work. Ive tried:

$data->code->data->accountEquity

$data[1]->accountEquity

$data->code->data->accountEquity

What is the right format to get those other values?

Thank you. gr Mike

Aram Becker
  • 2,026
  • 1
  • 20
  • 32
Mike
  • 1
  • Try restructuring your debug output, you'll see the solution pretty quickly then (I have edited your question). Otherwise, it would most likely help you to use a debugger for whatever IDE you are working with. Just Google "debug php with [your ide here]" – Aram Becker Jul 28 '21 at 10:52
  • Welcome to Stackoverflow. Please read how to [ask a good question](https://stackoverflow.com/help/how-to-ask) and provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) preferably in a [Stack snippet](https://stackoverflow.blog/2014/09/16/introducing-runnable-javascript-css-and-html-code-snippets/) – Timothy Alexis Vass Jul 28 '21 at 16:01

2 Answers2

1

The best way to get accountEquity is

$data->data->accountEquity
Rahul
  • 35
  • 5
0

The right way to access accountEquity is:

$data->data->accountEquity

But you could also cast the object to an array with:

$data = (array) $data;

Then accountEquity is reached by:

$data['data']['accountEquity']
wayneOS
  • 1,427
  • 1
  • 14
  • 20
  • Glad i could help and welcome to SO. Please select my answer so the question is finished. Happy coding. – wayneOS Jul 28 '21 at 07:30