很多站长朋友们都不太清楚php表格输出数组,今天小编就来给大家整理php表格输出数组,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 php怎么用print_r()以表格的形式输出数组 2、 php 怎么把数组输出到表单里 3、 php写一个数组用html表格输出这个数组 4、 php中怎么打印数组啊? 5、 PHP里如何以表格形式输出二维数组? php怎么用print_r()以表格的形式输出数组<?
//打印表格
print_r("<table>");
for($a=0;$a<count($row);$a++)
{
print_r("<tr>");
print_r("<td>".$row[$a][xm]."</td>");
print_r("<td>".$row[$a][yhm]."</td>");
print_r("<td>".$row[$a][yy]."</td>");
print_r("<td>".$row[$a][gs]."</td>");
print_r("<td>".$row[$a][cyy]."</td>");
print_r("</tr>");
}
print_r("</table>");
?>
php 怎么把数组输出到表单里html中不存在数组的说法, 自然也无法显示、保存、发送数组
如果你非要用html中的表单元素来发送多维数组数据,那就得转换一下,
1、将php数组循环遍历成字符串输出到隐藏域的value属性中
2、在隐藏域的name属性上做文章!
示例如下:
?php
foreach ( $item as $key =
$val )
?>
]['order_account']" value="
?php echo $val['order_account'] ?
">
]['money']" value="
?php echo $val['money'] ?
">
?php
}
?
php写一个数组用html表格输出这个数组1、首先输入:
<?php
class xtable
{
private $tit,$arr,$fons,$sextra;
public function __construct()
{
$this->tit=array(); // strings with titles for first row
$this->arr=array(); // data to show on cells
$this->fons=array("#EEEEEE","#CCEEEE"); // background colors for odd and even rows
$this->sextra=""; // extra html code for table tag
}
2、然后输入
public function extra($s) // add some html code for the tag table
{
$this->sextra=$s;
}
public function background($arr) {if (is_array($arr)) $this->fons=$arr; else $this->fons=array($arr,$arr);}
public function titles($text,$style="") {$this->tit=$text; $this->sesttit=$style;}
public function addrow($a) {$this->arr[]=$a;}
public function addrows($arr) {$n=count($arr); for($i=0;$i<$n;$i++) $this->addrow($arr[$i]);}
public function html()
3、然后输入:
{
$cfondos=$this->fons;
$titulos="<tr>";
$t=count($this->tit);
for($k=0;$k<$t;$k++)
{
$titulos.=sprintf("<th>%s</th>",$this->tit[$k])
}
$titulos.="</tr>";
$celdas="";
$n=count($this->arr);
for($i=0;$i<$n;$i++)
4、然后输入:
{
$celdas.=sprintf("<tr style='background-color:%s'>",$this->fons[$i%2]);
$linea=$this->arr[$i];
$m=count($linea);
for($j=0;$j<$m;$j++)
$celdas.=sprintf("<td %s>%s</td>","",$linea[$j]);
$celdas.="</tr>";
}
return sprintf("<table cellpadding='0' cellspacing='0' border='1' %s>%s%s</table>",$this->sextra,$titulos,$celdas);
}
public function example()
{
$tit=array("Apellidos","Nombre","Telefono");
$r1=array("Garcia","Ivan","888");
$r2=array("Marco","Alfonso","555");
$x=new xtable();
$x->titles($tit); //take titles array
$x->addrows(array($r1,$r2)); // take all rows at same time
return $x->html(); //return html code to get/show/save it
}
}
5、然后输入:
// Example
$t1=new xtable();
echo $t1->example()."<hr />";
$t2=new xtable();
for($i=1;$i<=10;$i+=2)
{
$t2->addrow(array("ODD",$i));
$t2->addrow(array("EVEN",$i+1));
}
6、然后输入:
$t2->background(array("pink","gold"));
$t2->titles(array("TYPE","#"));
$t2->extra(" style='width:500px; background-color:cyan; color:navy;'");
echo $t2->html()."<hr />";
$t3=new xtable();
for($i=1;$i<=6;$i++)
{
$t3->addrow(array("5x".$i,5*$i));
}
7、然后输入:
$t3->background(array("olive","maroon"));
$t3->titles(array("Multiplication table","5"));
$t3->extra("style='border:dotted red 10px; padding-left:4px;padding-right:4px; text-align:right;width:500px; background-color:black; color:white;'");
echo $t3->html()."<hr />";
$t4=new xtable();
$a=array("#");
for($i=1;$i<=10;$i++)
{
$a[]=$i;
}
8、然后输入:
$t4->addrow($a);
$t4->background(array("pink","gold"));
$tit=array(); $tit[]="Numbers";
for($i=1;$i<=10;$i++) $tit[]="#";
$t4->titles($tit);
$t4->extra("style='border:solid 1px silver; padding-left:4px;padding-right:4px; text-align:center;width:500px; background-color:cyan; color:navy;'");
echo $t4->html()."<hr />";
?>
9、然后就完成了。
php中怎么打印数组啊?php中打印数组的步骤如下:
1、首先在编辑器中的菜单栏中点击文件,然后点击新建。
2、点击新建菜单后,会弹出新建文档窗口,选择动态页,选择之后再选择php,然后点击”创建“。
3、点击创建后会建立一个临时的文件,按ctrl+s 会让你保存该文件,命名后保存在站点下。
4、在页面的body中加入php标识<?php ?>,在标签中创建一个简单的一维数组。
5、打印数组得用到循环,那么就得知道数组的长度,用count来获取数组的长度。
6、用for循环打印数组设置i默认值为0 ,i小于数组的长度,i自加,在echo中加入提示。
7、此时就成功地在php中打印数组了。
PHP里如何以表格形式输出二维数组?代码如下,这里使用了PHP的模板语法:
<?php
$array = array(
array('one', 'two', 'three'),
array('blue', 'red', 'yellow'),
array('apple', 'banana', 'pear'),
);
?>
<table>
<?php foreach ($array as $row): ?>
<tr>
<?php foreach ($row as $str): ?>
<td><?php echo $str; ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>
如有帮助,请点击采纳按钮,谢谢支持~
关于php表格输出数组的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于php表格输出数组 php打印数组中的值的详细内容...