0

I use Binance API. The PHP function gets file contents of url:

https://api.binance.com/api/v1/klines?symbol=BTCUSDT&interval=4h&limit=1

I receive such a response:

[[1528545600000,"7635.01000000","7650.00000000","7566.00000000","7621.15000000","3246.04484200",1528559999999,"24674635.12120312",57351,"1932.28202000","14685353.70584041","0"]]

How to get the second value? (7635.01000000)

hygull
  • 8,464
  • 2
  • 43
  • 52

1 Answers1

0

If you want to get the second value use this:

$receivedData = '[[1528545600000,"7635.01000000","7650.00000000","7566.00000000","7621.15000000","3246.04484200",1528559999999,"24674635.12120312",57351,"1932.28202000","14685353.70584041","0"]]';

$jsonDecodeData = json_decode($receivedData); 

$secondValue = jsonDecodeData[0][1];

echo $secondValue; //7635.01000000
Suraj Rana
  • 70
  • 13
  • This is the reason why I ask the question. I have tried json_decode, but the problem is that JSON doesn't accept "[ ]" brackets. So I get such an error: Notice: Undefined offset: 1 in C:\xampp\htdocs\index.php on line 64 –  Jun 11 '18 at 16:43
  • what do you mean by JSON doesn't accept "[ ]" brackets? can you please explain with an example. – Suraj Rana Jun 11 '18 at 17:01
  • jsonDecodeData just returns what is written in receivedData. But I have solved the problem with str_replace and regex. –  Jun 11 '18 at 19:09