PHP 打印阵列
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 打印阵列相关的知识,希望对你有一定的参考价值。
function printArray($arrayToPrint)
{
if(is_array($arrayToPrint)==true)
{
$i=1;
echo "<table border=1>";
$prevFieldNameStr="";
foreach ($arrayToPrint as $key=>$row) //gia kathe row...
{
$fieldNameStr="";
$fieldValueStr="";
echo "\n<tr>";
if (count($row)>1)
{
foreach ($row as $fieldName=>$fieldValue) //gia kathe field...
{
if (is_array($fiedValue))
{
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
if (strcmp($fieldNameStr,$prevFieldNameStr)==0)
{
}
else
{
echo "<td>A/A</td>";
echo $fieldNameStr;
$prevFieldNameStr=$fieldNameStr;
}
echo "</tr>\n<tr>";
echo "<td>$key</td>". $fieldValueStr;
echo "</tr>";
}
echo "</table>\n";
}
else
{
throw new Exception("The given parameter is not an array");
}
}
以上是关于PHP 打印阵列的主要内容,如果未能解决你的问题,请参考以下文章