note 29165 modified in function.array-keys by vincent
| From: | vincent@php.net | Date: | Fri, 29 Aug 2003 16:23:54 +0000 |
| Subject: | note 29165 modified in function.array-keys by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-55311@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.
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://www.php.net/manual/en/function.array-keys.php