fork download
  1. <?php
  2.  
  3. function test($str, $first=true) {
  4. if (!is_array($str)) {
  5. $result = "<li>$str</li>";
  6. } else {
  7. foreach ($str as $key => $value) $result .= test($value, false);
  8. }
  9. return ($first ? "<ol>$result</ol>" : $result);
  10. }
  11.  
  12. echo test("apple") . "\n";
  13. echo test(array("apple","orange","pear"));
  14.  
  15. ?>
Success #stdin #stdout 0.02s 13064KB
stdin
Standard input is empty
stdout
<ol><li>apple</li></ol>
<ol><li>apple</li><li>orange</li><li>pear</li></ol>