function test($str) {
$c = count($str);
if ($c>1) {
foreach ($str as $key => $value) $result .= test($value);
} else {
$result = "<li>$str</li>\n";
}
echo $result ? "<ol>$result</ol>" : null;
}
The $str value could be either, something like this;
$str1 = "apple";
or something like that;
$str2 = array("apple","orange","pear");
If count($str) is more than one, which is $str is is_array, it repeats the $result.
But it doesn’t work as I want..
I get an error “Cannot redeclare test() (previously declared in…”
The ideal output would be – $str1;
<ol>
<li>apple</li>
</ol>
The ideal output would be – $str2;
<ol>
<li>apple</li>
<li>orange</li>
<li>pear</li>
</ol>
Check, if
$stris an array, e.g.:Also see this example.
=== UPDATE ===
If you want to let it print directly, replace with:
Also see this example.