3v4l.org

run code in 300+ PHP versions simultaneously
<?php function HTMLStringify($arr, array $seen = array()) { if (is_array($arr)) { $seen[] = $arr; $html = '<ul>'; foreach ($arr as $key => $value) { $html .= '<li>' . $key; if (is_array($value)) { if (in_array($value, $seen, true)) { // Deal with recursion in your own way here $html .= ' [RECURSION]'; } else { $html .= HTMLStringify($value, $seen); } } elseif (is_numeric($value) || is_string($value) || is_null($value)) { $html .= ' = ' . $value; } else { $html .= ' [couldn\'t parse ' . gettype($value) . ']'; } $html .= '</li>'; } return $html . '</ul>'; } else { return null; } } $arr = array(1 => 'one', 2 => 'two'); $arr[3] = &$arr; echo HTMLStringify($arr);

preferences:
41.38 ms | 405 KiB | 5 Q