3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function loop($array) { echo '<ol class="dd-list">'; echo "\n"; foreach ( $array as $key => $value ) { echo '<li class="dd-item" data-id="' . $key . '">'; if(is_array($value)) { loop($value); } else { echo '<div class="dd-handle">' . $key . ' => ' . $value . '</div>'; } echo '</li>'; echo "\n"; } echo '</ol>'; } $testArray = array('1', '2', array('3', '4')); loop($testArray);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
<ol class="dd-list"> <li class="dd-item" data-id="0"><div class="dd-handle">0 => 1</div></li> <li class="dd-item" data-id="1"><div class="dd-handle">1 => 2</div></li> <li class="dd-item" data-id="2"><ol class="dd-list"> <li class="dd-item" data-id="0"><div class="dd-handle">0 => 3</div></li> <li class="dd-item" data-id="1"><div class="dd-handle">1 => 4</div></li> </ol></li> </ol>