//Сама строка где я и ищу
{"stream":"xrpusdt@bookTicker","data":{"u":10936805954,"s":"XRPUSDT","b":"0.64420000","B":"3076.00000000","a":"0.64440000","A":"6180.00000000"}}
//и также в таком виде
Array ( [stream] => xrpusdt@bookTicker [data] => Array ( [u] => 10937005616 [s] => XRPUSDT [b] => 0.64740000 [B] => 1053.00000000 [a] => 0.64750000 [A] => 118958.00000000 ) )
$message2 = json_decode($message, true);
foreach($message2 as $index => $value)
{
}
$pr=$message2[$index]['s'];
if($pr=='XRPUSDT'){$pr2=$message2[$index]['b'];}
echo'Test pr-----: ' .$pr.'<br>'; // выводит XRPUSDT
echo'Test pr-----: ' .$pr2.'<br>'; // выводит 0.64420000
<?php
$streams = [
'{"stream":"xrpusdt@bookTicker","data":{"u":10936805954,"s":"XRPUSDT","b":"0.64420000","B":"3076.00000000","a":"0.64440000","A":"6180.00000000"}}',
'{"stream":"xrpusdt@bookTicker","data":{"u":10936805954,"s":"BNBUSDT","b":"0.64420000","B":"3076.00000000","a":"0.64440000","A":"6180.00000000"}}'
];
$result = [];
foreach($streams as $json_str) {
$data = json_decode($json_str, true); //сама строка json в которой ищем
//var_dump($data['data']);
if(in_array($data['data']['s'], [
'XRPUSDT',
'BNBUSDT',
])) {
$result[$data['data']['s']] = $data['data']['b'];
}
}
print_r($result);
Array
(
[XRPUSDT] => 0.64420000
[BNBUSDT] => 0.64420000
)