3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json_data = '[ {"name":"Location 1","gigs": {"start":"16:30","end":"21:15","title":"TestTitle1","class":"fri"} }, {"name":"Location 2","gigs": {"start":"15:00","end":"19:00","title":"TestTitle2","class":"fri"} }, {"name":"Location 1","gigs": {"start":"21:00","end":"22:00","title":"TestTitle3","class":"fri"} } ]'; $arr = json_decode($json_data,true); $new_array = array(); foreach ($arr as $key => $value) { if(isset($new_array[$value['name']])) $new_array[$value['name']]['gigs'][] = $value['gigs']; //add already array existing value else{ $new_array[$value['name']]['name'] = $value['name']; $new_array[$value['name']]['gigs'][] = $value['gigs']; //create array } } $new_array = array_values($new_array); //to remove keys echo json_encode($new_array);
Output for git.master, git.master_jit, rfc.property-hooks
[{"name":"Location 1","gigs":[{"start":"16:30","end":"21:15","title":"TestTitle1","class":"fri"},{"start":"21:00","end":"22:00","title":"TestTitle3","class":"fri"}]},{"name":"Location 2","gigs":[{"start":"15:00","end":"19:00","title":"TestTitle2","class":"fri"}]}]

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