<?php

function test($str, $first=true) {
  if (!is_array($str)) $result = "<li>$str</li>";
  else foreach ($str as $key => $value) $result .= test($value, false);
  if ($first) echo "<ol>$result</ol>";
  else return $result;
}

test("apple");
echo "\n";
test(array("apple","orange","pear"));

?>