note 22364 added to ref.array
| From: | spam@php.net | Date: | Fri, 14 Jun 2002 23:50:20 +0000 |
| Subject: | note 22364 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-31874@lists.php.net to get a copy of this message | ||
I want to share a VERY usefull way to debug php and arrays:
just create a file like array.func.inc.php
paste the following code into the file.
// To make ANY array visible ...
function viewArray($arr)
{
echo '<table cellpadding="0" cellspacing="0"
border="1">';
foreach ($arr as $key1 => $elem1) {
echo '<tr>';
echo '<td>'.$key1.' </td>';
if (is_array($elem1)) { extArray($elem1); }
else { echo '<td>'.$elem1.' </td>'; }
echo '</tr>';
}
echo '</table>';
}
function extArray($arr)
{
echo '<td>';
echo '<table cellpadding="0" cellspacing="0"
border="1">';
foreach ($arr as $key => $elem) {
echo '<tr>';
echo '<td>'.$key.' </td>';
if (is_array($elem)) { extArray($elem); }
else { echo
'<td>'.htmlspecialchars($elem).' </td>'; }
echo '</tr>';
}
echo '</table>';
echo '</td>';
}
close the file and include that file into any other php document. If u want to check the content of
an array just type viewarray($array);
--
http://www.php.net/manual/en/ref.array.php
http://master.php.net/manage/user-notes.php?action=edit+22364
http://master.php.net/manage/user-notes.php?action=delete+22364
http://master.php.net/manage/user-notes.php?action=reject+22364