<?php
$json = file_get_contents('730.json');
$skobka1 = "{";
$skobka0 = '"prices" : [';
$skobka2 = "]";
$skobka3 = "}";
@file_put_contents('opskins.json', $skobka1 . PHP_EOL, FILE_APPEND);
@file_put_contents('opskins.json', $skobka0 . PHP_EOL, FILE_APPEND);
$data = json_decode($json, true);
foreach ($data as $name => $value) {
$fruit = array_pop($value);
$fruit2 = array_shift($fruit);
$vivod = '{'.'"market_hash_name" : '.'"'.$name.'","price" : "'.$fruit2.'"},';
@file_put_contents('opskins.json', $vivod . PHP_EOL, FILE_APPEND);
}
@file_put_contents('opskins.json', $skobka2 . PHP_EOL, FILE_APPEND);
@file_put_contents('opskins.json', $skobka3 . PHP_EOL, FILE_APPEND);
?>
Как убрать запятую в конце массива?
{
"prices" : [
{"market_hash_name" : "AK-47 | Aquamarine Revenge (Battle-Scarred)","price" : "777"},
{"market_hash_name" : "AK-47 | Aquamarine Revenge (Factory New)","price" : "3132"},
{"market_hash_name" : "AK-47 | Aquamarine Revenge (Field-Tested)","price" : "1510"},
{"market_hash_name" : "AK-47 | Aquamarine Revenge (Minimal Wear)","price" : "2202"},
{"market_hash_name" : "AK-47 | Aquamarine Revenge (Well-Worn)","price" : "1089"},
]
}