- is_numeric: documentation ( source)
- in_array: documentation ( source)
<?php
function HTMLStringify(&$arr, $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))
{
$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>';
}
$html .= '</ul>';
return $html;
}
else
{
return null;
}
}
$arr = array(1 => 'one', 2 => 'two');
$arr[3] = &$arr;
echo HTMLStringify($arr);