note 29165 modified in function.array-keys by vrana

From: Date: Tue, 17 Aug 2004 13:58:29 +0000
Subject: note 29165 modified in function.array-keys by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-80073@lists.php.net to get a copy of this message
[Editor's note: For a complete solution to the printing of complex structures or hashes, see the PEAR::Var_Dump package: http://pear.php.net/package-info.php?pacid=103 , use "pear install Var_Dump" to get it] 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. <?php 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); ?> --was-- [Editor's note: For a complete solution to the printing of complex structures or hashes, see the PEAR::Var_Dump package: http://pear.php.net/package-info.php?pacid=103 , use "pear install Var_Dump" to get it] 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://php.net/manual/en/function.array-keys.php

« previous php.notes (#80073) next »