/ Published in: PHP
Function printing the contents of an array. Similar to var_dump but better looking. As it shows a table... Great for debug.
Expand |
Embed | Plain Text
function printArray($arrayToPrint) { { $i=1; echo "<table border=1>"; $prevFieldNameStr=""; foreach ($arrayToPrint as $key=>$row) //gia kathe row... { $fieldNameStr=""; $fieldValueStr=""; echo "\n<tr>"; { foreach ($row as $fieldName=>$fieldValue) //gia kathe field... { { foreach ($fieldValue as $f=>$v) { $fieldNameStr.="<td><b>" . $f . "</b></td>"; $fieldValueStr.="<td>" . $v. "</td>"; } } else { $fieldNameStr.="<td><b>" . $fieldName . "</b></td>"; $fieldValueStr.="<td>" . $fieldValue. "</td>"; } } } else { $fieldValueStr.="<td>" . $row. "</td>"; } //prints fieldNames only if they are different { } else { echo "<td>A/A</td>"; echo $fieldNameStr; $prevFieldNameStr=$fieldNameStr; } echo "</tr>\n<tr>"; echo "</tr>"; } echo "</table>\n"; } else { throw new Exception("The given parameter is not an array"); } }
You need to login to post a comment.
