note 29165 added to function.array-keys

From: Date: Tue, 04 Feb 2003 22:39:10 +0000
Subject: note 29165 added to function.array-keys
Groups: php.notes 
Request: Send a blank email to php-notes+get-43415@lists.php.net to get a copy of this message
This function will print all the keys of a multidimensional array in html tables. It will help to debug when you don´t have control of depths. function show_keys($ar){ echo "<table width='100%' border='1' bordercolor='#6699CC' cellspacing='0' cellpadding='5'><tr valign='top'>"; foreach ($ar as $k => $v ) { echo "<td align='center' bgcolor='#EEEEEE'> <table border='2' cellpadding='3'><tr><td bgcolor='#FFFFFF'><font face='verdana' size='1'> " . $k . " </font></td></tr></table>"; if (is_array($ar[$k])) { show_keys ($ar[$k]); } echo "</td>"; } echo "</tr></table>"; } // Multidimensional array -> $arvore = array(); $arvore['1'] = array(); $arvore['1']['1.1'] = array('1.1.1', '1.1.2', '1.1.3'); $arvore['1']['1.2'] = array('1.2.1', '1.2.2', '1.2.3'); $arvore['1']['1.3'] = array('1.3.1', '1.3.2', '1.3.3'); $arvore['2'] = array(); $arvore['2']['2.1'] = array('2.1.1', '2.1.2', '2.1.3'); $arvore['2']['2.2'] = array('2.2.1', '2.2.2', '2.2.3'); $arvore['2']['2.3'] = array('2.3.1', '2.3.2', '2.3.3'); $arvore['3'] = array(); $arvore['3']['3.1'] = array('3.1.1', '3.1.2', '3.1.3'); $arvore['3']['3.2'] = array('3.2.1', '3.2.2', '3.2.3'); $arvore['3']['3.3'] = array('3.3.1', '3.3.2'=>array('3.3.2.1', '3.3.2.2'), '3.3.3'); // <- show_keys($arvore); -- http://www.php.net/manual/en/function.array-keys.php http://master.php.net/manage/user-notes.php?action=edit+29165 http://master.php.net/manage/user-notes.php?action=delete+29165 http://master.php.net/manage/user-notes.php?action=reject+29165

« previous php.notes (#43415) next »