我正在尝试使以下 PHP 函数在带自动换行的 CSS 滚动文本框中工作(这是整个程序示例——没有其他 CSS)。
<?php
function prettyPrint( $my_array ) {
if (is_array($my_array)) {
echo "<table style=border=0 cellspacing=2 cellpadding=1 width=100%>";
echo '<tr><td colspan=2 style="background-color:#B29980;"></td></tr>';
foreach ($my_array as $k => $v) {
if (is_int($k)){$k=$k+1;}
echo '<tr><td valign="top" style="width:20px;background-color:#F0F0F0;">';
echo '<strong>' . " " . $k . " " . "</strong></td><td>";
prettyPrint( $v ) ;
echo "</td></tr>";
}
echo '<tr><td colspan=2 style="background-color:#B29980;"></td></tr>';
echo "</table>";
return;
}
echo $my_array;
}
$array = array( array ( "Txt1" => "Lorem ipsum dolor sit amet...
"Txt2" => "Lorem ipsum dolor sit amet...
array ( "Txt3" => "Lorem ipsum dolor sit amet...
"Txt4" => "Lorem ipsum dolor sit amet...
prettyPrint($array);
?>
我试过在第 3 行添加这个:
echo '<div style="height:250px; width:980px; overflow:auto; overflow-x: hidden">';
这个 div 标签在分组元素之间添加了很大的空间间隙,也没有自动换行。如何获取函数的输出并将其显示在自动换行的滚动文本框中?
预先感谢您的帮助。
最佳答案
据我了解,您想要 <div>
- 围绕一切的容器,对吧?
喜欢...
____________ this is the <div> ________________
| |
| inside here is the nested table |
| with text 1 to text 4 |
|______________________________________________|
然后去:
echo '<div style="height:250px; width:980px; overflow:auto; overflow-x: hidden">';
prettyPrint($array);
echo '</div>';
您的函数 prettyPrint 是递归的,这意味着它会被多次调用。如果您包括 <div>
在那里,你最终会得到几个 <div>
- 嵌套表中的容器,这是一团糟。
关于php - 多列关联数组的 CSS 格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15605004/