Over a million developers have joined DZone.

Get HTML List Of Array Keys

DZone's Guide to

Get HTML List Of Array Keys

Free Resource
Sometimes I find it useful having an overview about the keys an array has; PHP function Get_Array_Keys_UL will create an nested HTML Unordered List string of the keys of a given array. Makes best sense with literal keys, e.g. $_POST:

 * Creates recursively a nested HTML UL of array keys.
 * @param array $array Array
 * @return string Nested UL string
function Get_Array_Keys_UL($array=array()) {
 if (empty($array)) return '';
    '."\n"; foreach ($array as $key => $elem) $out .= '
  • '.$key.$recursion($elem).'
  • '."\n"; $out .= '
'."\n"; return $out; }
Use like this: $ul=Get_Array_Keys_UL($_POST); echo $ul;

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}