<?php

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

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

?>