3v4l.org

run code in 300+ PHP versions simultaneously
<?php // $result = $conn->query("SELECT content, sub_content FROM objectives"); $result = [ ["content" => "Demonstrate where to find the following documentation:", "sub_content" => "Operating and Safety Strategy"], ["content" => "Explain the different turbine main operating states:", "sub_content" => "0"], ["content" => "Explain the different turbine main operating states:", "sub_content" => "Power Production"], ["content" => "Explain the different turbine main operating states:", "sub_content" => "Idle"], ["content" => "Explain the different turbine main operating states:", "sub_content" => "Stop"], ["content" => "Explain how to recognise the current operating mode on the display of the operating panel", "sub_content" => "0"], ["content" => "Explain the subsystem operating modes:", "sub_content" => "Stop"], ["content" => "Explain the subsystem operating modes:", "sub_content" => "Manual"], ["content" => "Explain the subsystem operating modes:", "sub_content" => "0"], ["content" => "Explain the difference between local and remote point of operation", "sub_content" => "0"], ["content" => "Explain that only one point of operation can be active at a time", "sub_content" => "0"] ]; $category = null; $output = ''; foreach ($result as $row) { if ($category !== $row['content']) { // new parent if ($category !== null) { // not first iteration $output .= "\t<li>$category"; // print parent if ($sublist) { $output .= "\n\t\t<ul>$sublist\n\t\t</ul>\n\t"; // print all children } $output .= "</li>\n"; } $category = $row['content']; // overwrite $category $sublist = ''; // reset sublist } if ($row['sub_content'] !== '0'){ // filter row $sublist .= "\n\t\t\t<li>{$row['sub_content']}</li>"; } } if ($result) { // in case the resultset is empty echo "<ul>\n"; echo $output; // print stored markup echo "\t<li>$category"; // print last parent if ($sublist) { echo "\n\t\t<ul>$sublist\n\t\t</ul>\n\t"; // print all children from last parent } echo "</li>\n"; echo "</ul>"; }
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.4.16, 8.5.0 - 8.5.1
<ul> <li>Demonstrate where to find the following documentation: <ul> <li>Operating and Safety Strategy</li> </ul> </li> <li>Explain the different turbine main operating states: <ul> <li>Power Production</li> <li>Idle</li> <li>Stop</li> </ul> </li> <li>Explain how to recognise the current operating mode on the display of the operating panel</li> <li>Explain the subsystem operating modes: <ul> <li>Stop</li> <li>Manual</li> </ul> </li> <li>Explain the difference between local and remote point of operation</li> <li>Explain that only one point of operation can be active at a time</li> </ul>
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
182.62 ms | 408 KiB | 5 Q