我想从一个组织为 Key => value 的数组中填充一个 html 表,我使用 zend 框架,我的问题是当我必须在 html 代码中打印它们时,Php 不尊重数组中值的顺序这是我的控制器:
<?php
class Dashboard_LogsController extends Dashboard_Library_Custom_Controller_Dashboard
{
function array_merge_rec($arrays)
{
$result = array();
$keys = array('delivred','open', 'click', 'unsubscribe', 'soft', 'hard', 'deferred');
foreach ($arrays as $key => $value) {
if (is_array($value)) {
foreach ($value as $item) {
$result[$item['isp']][$key] = $item['count'];
}
}
}
$results = array();
foreach($result as $key => $value)
{
foreach($keys as $k)
{
if(!isset($result[$key][$k])) $result[$key][$k] = 0;
}
}
return $result;
}
public function logsAction()
{
$this->view->headLink()->appendStylesheet(STATIC_URL . '/css/bootstrap.datetimepicker.min.css');
$this->view->headScript()->appendFile(STATIC_URL . '/js/bootstrap.datetimepicker.min.js');
$log_review = new Dashboard_Model_DbTable_logs();
$open = $log_review->getOpen();
$click = $log_review->getClick();
$unsubscribe = $log_review->getUnsubscribe();
$deferred = $log_review->getDeferred();
$delivred = $log_review->getSent();
$SB = $log_review->getSB();
$HB = $log_review->getHB();
$result = $this->array_merge_rec(array('delivred'=>$delivred,'open' => $open, 'click' => $click, 'unsubscribe' => $unsubscribe, 'hard' => $HB, 'soft' => $SB, 'deferred'=>$deferred));
$this->view->data = $result;
}
}
我用来在屏幕上显示表格的 html 代码如下:
<div class="row-fluid">
<div class="span12 meter-legend meter-statistics">
<table>
<tr>
<th>ISP</th><th>Email address</th><th>Delivred</th><th>Open</th><th>Clicks</th><th>Unsubscribed</th><th>Hard</th><th>Soft</th><th>Deferred</th>
</tr>
<?php foreach($this->data as $name => $isp) { ?>
<?php
$sum =0;
foreach($isp as $key => $value) {
$sum =$sum+$value;
}
if ($sum >= 500) {?>
<tr>
<td><?php echo $name; ?></td>
<td><?php echo $sum; ?></td>
<?php foreach($isp as $key => $value) { ?>
<td><?php echo $value; ?></td>
<?php } ?>
</tr>
<?php } ?>
<?php } ?>
</table>
所以这段代码填充了表格,但不尊重列的顺序,我真的不知道 php 是如何做到这一点的。我的问题是,如果有人能告诉我如何在第一次...重复中打印数组中的第一个结果。而且我不知道我是否可以使用键来选择数组值,但是如果可以的话,我真的不知道该怎么做。