3v4l.org

run code in 300+ PHP versions simultaneously
<?php // okay I was wondering something about loops // say I wanted to get all comments from a db // that's easy with a `foreach` loop // but what if I want to get a reply for each comment in that foreach loop? // well I'd have to put a foreach loop within a foreach loop, no biggy. // but what happens if you'd want an infinite checker that checks a reply // ect. e.g: foreach($comments as $comment) { // output comment // say the nest_id is the id of a comment and the nest_id // is nested as a comment's reply // this is easy foreach($comment->nest_id as $comment_nest) { } } // basically is it possible to loop through something, // then automatically loop another time if there is a reply to a comment // and if there is a reply to that reply then automatically get that? // seems rather complicated.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Warning: Undefined variable $comments in /in/c44dC on line 11 Warning: foreach() argument must be of type array|object, null given in /in/c44dC on line 11
Output for 5.6.0 - 5.6.29, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.5 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined variable: comments in /in/c44dC on line 11 Warning: Invalid argument supplied for foreach() in /in/c44dC on line 11
Output for 7.3.32 - 7.3.33
Warning: Invalid argument supplied for foreach() in /in/c44dC on line 11

preferences:
111.6 ms | 1549 KiB | 4 Q