3v4l.org

run code in 500+ PHP versions simultaneously
<?php $json = '{"lenght":0,"subcategory":[]}'; $last_id = 123; $obj = json_decode($json, true); array_push($obj["subcategory"], $last_id); $obj["lenght"] = (int)$obj["lenght"] + 1; $json = json_encode($obj); echo $json;

preferences:
45.12 ms | 1376 KiB | 5 Q