3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getComments(int $parentId = null): array { $comments = [ ['id' => 1, 'parentId' => null, 'comment' => 'foo'], ['id' => 2, 'parentId' => null, 'comment' => 'bar'], ['id' => 3, 'parentId' => 1, 'comment' => 'foo 1'], ['id' => 4, 'parentId' => 1, 'comment' => 'foo 2'], ['id' => 5, 'parentId' => 4, 'comment' => 'foo 2-1'], ['id' => 6, 'parentId' => 2, 'comment' => 'foo bar'], ['id' => 7, 'parentId' => 5, 'comment' => 'foo 2-1-1'], ]; return array_filter($comments, fn (array $comment): bool => $comment['parentId'] === $parentId); } function showComments(?int $parentId = null, int $level = 0) { foreach (getComments($parentId) as $comment) { printf('%sComment id: %d - comment %s', str_repeat(' ', $level), $comment['id'], $comment['comment']); echo "\n"; showComments($comment['id'], $level + 1); } } showComments();
Output for git.master, git.master_jit, rfc.property-hooks
Comment id: 1 - comment foo Comment id: 3 - comment foo 1 Comment id: 4 - comment foo 2 Comment id: 5 - comment foo 2-1 Comment id: 7 - comment foo 2-1-1 Comment id: 2 - comment bar Comment id: 6 - comment foo bar

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:
129.8 ms | 406 KiB | 5 Q