3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '{ "data": { "id": 2, "title": "second evaluation form", "emp_position": "System Architecture", "rating": 5, "segments": [ { "segment_name": "Job Role ", "question": "How old are you?" }, { "segment_name": "360 Segments", "question": "What is your food?" }, { "segment_name": "360 Segments", "question": "sample question" } ] } }'; $data = json_decode($json,true); $segments = $data['data']['segments']; $new_segemnts = array(); foreach($segments as $segemnt) { $key = $segemnt['segment_name']; $new_segemnts[$key]['segment_name']=$segemnt['segment_name']; $new_segemnts[$key]['question_collection'][]=array("question"=>$segemnt['question']); } $data['data']['segments'] = array_values($new_segemnts); echo json_encode($data,JSON_PRETTY_PRINT);
Output for git.master, git.master_jit, rfc.property-hooks
{ "data": { "id": 2, "title": "second evaluation form", "emp_position": "System Architecture", "rating": 5, "segments": [ { "segment_name": "Job Role ", "question_collection": [ { "question": "How old are you?" } ] }, { "segment_name": "360 Segments", "question_collection": [ { "question": "What is your food?" }, { "question": "sample question" } ] } ] } }

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:
36.03 ms | 402 KiB | 8 Q