3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json_str='{ "code": 200, "message": "操作成功", "data": [ { "id": 1, "goods_id": 1, "property_name_id": 1, "property_value_id": 1, "property_name": { "title": "份量", "is_sale": true }, "property_value": { "id": 1, "value": "小份", "image": "" } }, { "id": 2, "goods_id": 1, "property_name_id": 1, "property_value_id": 2, "property_name": { "title": "份量", "is_sale": true }, "property_value": { "id": 2, "value": "中份", "image": "" } }, { "id": 3, "goods_id": 1, "property_name_id": 2, "property_value_id": 4, "property_name": { "title": "温度", "is_sale": true }, "property_value": { "id": 4, "value": "常温", "image": "" } }, { "id": 4, "goods_id": 1, "property_name_id": 2, "property_value_id": 5, "property_name": { "title": "温度", "is_sale": true }, "property_value": { "id": 5, "value": "加冰", "image": "" } } ] }'; $obj = json_decode($json_str); $data = []; foreach($obj->data as $v){ $nid=$v->property_name_id; if(!array_key_exists($nid,$data)){ $o = new stdclass; $o->property_id = $v->property_name_id; $o->property_name = $v->property_name->title; $o->is_sale= $v->property_name->is_sale ; $data[$nid]=$o; } $data[$nid]->items[]=$v->property_value; } $obj->data = array_values($data); print_r($obj); //echo json_encode($obj);
Output for git.master, git.master_jit, rfc.property-hooks
stdClass Object ( [code] => 200 [message] => 操作成功 [data] => Array ( [0] => stdClass Object ( [property_id] => 1 [property_name] => 份量 [is_sale] => 1 [items] => Array ( [0] => stdClass Object ( [id] => 1 [value] => 小份 [image] => ) [1] => stdClass Object ( [id] => 2 [value] => 中份 [image] => ) ) ) [1] => stdClass Object ( [property_id] => 2 [property_name] => 温度 [is_sale] => 1 [items] => Array ( [0] => stdClass Object ( [id] => 4 [value] => 常温 [image] => ) [1] => stdClass Object ( [id] => 5 [value] => 加冰 [image] => ) ) ) ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
131.3 ms | 411 KiB | 5 Q