0

I am fairly new to php and have been experimenting with the mt. Gox (bitcoin exchange) API, but I do not understand the array result. Can someone explain the appropriate way to echo or print the [buy] element in php?

Thanks!

    Array
(
[result] => success
[data] => Array
    (

        [buy] => Array
            (
                [value] => 945.02000
                [value_int] => 94502000
                [display] => $945.02000
                [display_short] => $945.02
                [currency] => USD
            )

        [sell] => Array
            (
                [value] => 949.00000
                [value_int] => 94900000
                [display] => $949.00000
                [display_short] => $949.00
                [currency] => USD
            )

        [now] => 1389812614875071
    )

)

1

1 Answer 1

2

You have an array name $x.

For example you can do this: $x['data]['buy']['value'] to get that data.

or a foreach for the buy data:

if( $x['result'] == "success" ) {
    foreach( $x['data']['buy'] as $key => $value ) {
        echo $key . ": " . $value . "<br />";
    }
} else {
    echo "Error occured";
}

You can even have a foreach in a foreach. To loop through all data in the array.

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

Comments

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.