Get HTML list of Array Keys


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2.  * Creates recursively a nested HTML UL of array keys.
  3.  * @param array $array Array
  4.  * @return string Nested UL string
  5.  */
  6. function Get_Array_Keys_UL($array=array()) {
  7. $recursion=__FUNCTION__;
  8. if (empty($array)) return '';
  9. $out='<ul>'."\n";
  10. foreach ($array as $key => $elem)
  11. $out .= '<li>'.$key.$recursion($elem).'</li>'."\n";
  12. $out .= '</ul>'."\n";
  13. return $out;
  14. }
  15.  
  16.  
  17. $ul=Get_Array_Keys_UL($_POST);
  18. echo $ul;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.