Есть json массив такого вида, нужно вывести название и цену последней даты.
{"Name1":{"2016-06-22":{"price":677,"count":71},"2016-06-23":{"price":625,"count":67},"2016-06-24":{"price":628,"count":78}},"Name2":{"2016-06-22":{"price":2536,"count":46},"2016-06-23":{"price":2432,"count":40},"2016-06-24":{"price":2396,"count":142}}}
пытался вывести, но получаю вместо цены null.
function handle() {
$url = "730.json";
$content = file_get_contents($url);
$priceFull = json_decode($content);
$priceClear = [];
foreach ($priceFull AS $itemName => $itemPricesByDate) {
$oPrice = array_values($itemPricesByDate);
$oItem = [ $itemName => $oPrice[-1]['price'] ];
$priceClear[] = $oItem;
@file_put_contents('Update.log', json_encode($oItem) . PHP_EOL, FILE_APPEND);
}
$priceClearJson = json_encode($priceClear);
}
Нужно получать вывод вида:
[{"market_hash_name":"Name1","price":"6.28","updated":"2016-06-24"},{"market_hash_name":"Name2","price":"27.96","updated":"2016-06-24"}]