3v4l.org

run code in 300+ PHP versions simultaneously
<?php $postArray = array ( 0 => array ( 'id' => 1, 'post' => 'hello', 'userId' => 1, 'fileName' => 'hey.jpg', 'time' => 0, ), 1 => array ( 'id' => 1, 'post' => 'hello', 'userId' => 1, 'fileName' => 'test.png', 'time' => 53252354, ), 2 => array ( 'id' => 2, 'post' => 'world', 'userId' => 1, 'fileName' => 'asd.png', 'time' => 0, ), 3 => array ( 'id' => 4, 'post' => 'test', 'userId' => 1, 'fileName' => 'asd2.png', 'time' => 0, ), 4 => array ( 'id' => 3, 'post' => 'ouch', 'userId' => 2, 'fileName' => NULL, 'time' => NULL, ), ); foreach ($postArray as $post) { $fixed_part = array('id' => $post['id'], 'post' => $post['post'], 'userId' => $post['userId']); $key = serialize($fixed_part); if (!isset($out[$key])) $out[$key] = $fixed_part; $out[$key]['attachments'][] = array('fileName' => $post['fileName'], 'time' => $post['time']); } $out = array_values($out); echo json_encode($out, JSON_PRETTY_PRINT);
Output for git.master, git.master_jit, rfc.property-hooks
[ { "id": 1, "post": "hello", "userId": 1, "attachments": [ { "fileName": "hey.jpg", "time": 0 }, { "fileName": "test.png", "time": 53252354 } ] }, { "id": 2, "post": "world", "userId": 1, "attachments": [ { "fileName": "asd.png", "time": 0 } ] }, { "id": 4, "post": "test", "userId": 1, "attachments": [ { "fileName": "asd2.png", "time": 0 } ] }, { "id": 3, "post": "ouch", "userId": 2, "attachments": [ { "fileName": null, "time": null } ] } ]

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:
70.91 ms | 408 KiB | 5 Q