大佬教程收集整理的这篇文章主要介绍了PHP Array交叉表实现代码,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如果使用sql语句做的话 工作量太大了,于是尝试自己写一个交叉表的类,好二话不说,我们看看代码
<div class="codetitle"><a style="CURSOR: pointer" data="2903" class="copybut" id="copybut2903" onclick="doCopy('code2903')"> 代码如下:
';
print_r ( $this->pivotValue );
}
/
渲染为table
/
function RenderToTable()
{
$resault = "\n";
$resault .= "<tr><td>$this->title</td>\n";
foreach ( $this->verticalColumn as $value )
{
$resault .= "<td>$value</td>\n";
}
$resault .= "</tr>\n";
foreach ( $this->horizontalColumn as $i )
{
$resault .= "<tr><td>$i</td>\n";
foreach ( $this->pivotValue [$i] as $value )
{
$resault .= "<td>$value</td>\n";
}
$resault .= "</tr>\n";
}
$resault .= "</table>";
return $resault;
}
/
构造交叉表
@param $data 数据源
@param $topPivot 头栏目字段
@param $leftPivot 左栏目字段
@param $measure 计算量
/
function __construct(array $data,$topPivot,$leftPivot,$measure)
{
$this->data = $data;
$this->leftPivot = $leftPivot;
$this->topPivot = $topPivot;
$this->measure = $measure;
$this->horizontalColumn = array ();
$this->verticalColumn = array ();
$this->InitPivot ();
$this->fillData ();
}
}
重点在于InitPivot方法及fillData方法。
InitPivot里面保证了所有的item都会有值(默认为0)
fillData方法使用选择填充添加的方法,将数据填充入我们装数据的$pivotValue里面。 然后喜欢怎么输出都可以了大佬总结
以上是大佬教程为你收集整理的PHP Array交叉表实现代码全部内容,希望文章能够帮你解决PHP Array交叉表实现代码所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。猜你在找的PHP相关文章
- php实现mysql数据库分表分段备份 2019-11-12
- php – 将Symfony2 LogoutSuccessHandler重定向到原始注销目标 2019-10-03
- 用PHP读取图像中的文本 2019-10-03
- php – MySQL守护程序无法启动 – centos 6 2019-10-03
- 扩展PHP的类型提示 2019-10-03
- 如何在PHP中复制此C#散列? (toByteArray(),ComputeHash()) 2019-10-03
- php – 如何在Symfony2中禁用模板功能 2019-10-03
- 使用PHPUnit在Silex(mock closures)中进行测试 2019-10-03
- php – 仅使用“桌面模式”浏览器检测移动用户 2019-10-03
- PHP调用微博接口实现微博登录的方法示例 2022-04-09