Difficulty catching a json element with php

Asked

Viewed 29 times

-1

I have the following result in json:

Array
(
    [data] => Array
        (
            [charges] => Array
                (
                    [0] => Array
                        (
                            [code] => 70082972

I’d like to know how I get the element code with php.

I tried to:

echo $data["charges"][0]["code"];
echo $data->charges->code;

But to no avail.

  • 1

    have tried: echo $data["data"]["charges"][0]["code"]; ?

  • 1

    I just tried and it worked. Put as an answer for me to evaluate.

1 answer

1


Missed typing one of the keys to the arrays that is data and the final solution:

echo $data["data"]["charges"][0]["code"];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.