I
I
Ivan2018-11-03 08:47:08
PHP
Ivan, 2018-11-03 08:47:08

How to extract data from json multidimensional array?

Hello! Please help, I need to extract data from json array. I need to get the value of the rate
I'm trying to do this, but it doesn't work

$arr = json_decode($open_orders, true);
  $open_orders = $arr[0]['rate'];

And here is the array:
[
  {
    "id": "QPYRgfwiB9",
    "state": "opened",
    "type": "buy",
    "open_amount": 0.001,
    "amount": 0.001,
    "rate": 0.001,
    "price": 0.000001,
    "timestamp": 1498215757
  },
  ...
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
My joy, 2018-11-03
@t-alexashka

Maybe you messed up something with variable names or made an error in json because of which it is equal to Null. everything shows fine for me:

<?php

$json = '
[{
    "id": "QPYRgfwiB9",
    "state": "opened",
    "type": "buy",
    "open_amount": 0.001,
    "amount": 0.001,
    "rate": 0.001,
    "price": 0.000001,
    "timestamp": 1498215757
  },
  {
    "id": "QPYRgfwiB9",
    "state": "opened",
    "type": "buy",
    "open_amount": 0.001,
    "amount": 0.001,
    "rate": 0.002,
    "price": 0.000001,
    "timestamp": 1498215757
  }]';

$arr = json_decode($json, true);
echo $arr[0]['rate'];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question