我正在尝试使用数组对我的标题进行分类。但似乎我已经碰壁了。我的数组是数组中的一个数组,第一个数组保存 group_id,子数组包含有关标题的所有信息。我正在尝试的是在对应于 group_id 的表中返回数组。目前有第 1 组和第 2 组,但将来我会添加更多组。我被卡住的部分是我不能或者我不知道如何选择组的 id 及其在数组中的内容,以便它将显示在正确的表中。我的项目基于 Open cart。这是我到目前为止的代码:这是视图:
foreach($informations as $information)
{
echo '<table border="1"><tr><td>';
print_r($information);
echo '</table></tr></td>';
}
这是带有数组的控制器函数:
$information_total = $this->model_catalog_information->getTotalInformations();
$results = $this->model_catalog_information->getInformations($data);
foreach ($results as $result)
{
$action = array();
$action[] = array(
'text' => $this->language->get('text_edit'),
'href' => $this->url->link('catalog/information/update', 'token=' . $this->session->data['token'] . '&information_id=' . $result['information_id'] . $url, 'SSL')
);
$this->data['informations'][] = array( $result['groupe_id'] => array(
'information_id' => $result['information_id'],
'title' => $result['title'],
'master' => $result['master'],
'sort_order' => $result['sort_order'],
'selected' => isset($this->request->post['selected']) && in_array($result['information_id'], $this->request->post['selected']),
'action' => $action
));
}
Tnx 提前寻求帮助。抱歉,如果我解释得不够清楚,因为英语不是我的第一语言 :) 如果有什么我解释得不够清楚,请问我会回答。
这就是数组输出的内容:
Array
(
[1] => Array
(
[information_id] => 12
[title] => ABOUT USfdsfds
[master] => AND OTHERSfdsfds
[sort_order] => 0
[selected] =>
[action] => Array
(
[0] => Array
(
[text] => Edit
[href] => http://localhost/opencart/admin/index.php?route=catalog/information/update&token=be54d82da3beb8855eb80bc49a4b28a4&information_id=12
)
)
)
)
Array
(
[1] => Array
(
[information_id] => 17
[title] => dsfsdfds
[master] => fdsfdsf
[sort_order] => 0
[selected] =>
[action] => Array
(
[0] => Array
(
[text] => Edit
[href] => http://localhost/opencart/admin/index.php?route=catalog/information/update&token=be54d82da3beb8855eb80bc49a4b28a4&information_id=17
)
)
)
)
Array
(
[1] => Array
(
[information_id] => 14
[title] => eeee
[master] => eeeee
[sort_order] => 0
[selected] =>
[action] => Array
(
[0] => Array
(
[text] => Edit
[href] => http://localhost/opencart/admin/index.php?route=catalog/information/update&token=be54d82da3beb8855eb80bc49a4b28a4&information_id=14
)
)
)
)
Array
(
[2] => Array
(
[information_id] => 15
[title] => fffffffffffff
[master] => fffffffffffffff
[sort_order] => 0
[selected] =>
[action] => Array
(
[0] => Array
(
[text] => Edit
[href] => http://localhost/opencart/admin/index.php?route=catalog/information/update&token=be54d82da3beb8855eb80bc49a4b28a4&information_id=15
)
)
)
)
Array
(
[2] => Array
(
[information_id] => 13
[title] => Hello
[master] => Hello Again
[sort_order] => 0
[selected] =>
[action] => Array
(
[0] => Array
(
[text] => Edit
[href] => http://localhost/opencart/admin/index.php?route=catalog/information/update&token=be54d82da3beb8855eb80bc49a4b28a4&information_id=13
)
)
)
)
Array
(
[2] => Array
(
[information_id] => 16
[title] => ssssssssssssssss
[master] => ssssssssssssssss
[sort_order] => 0
[selected] =>
[action] => Array
(
[0] => Array
(
[text] => Edit
[href] => http://localhost/opencart/admin/index.php?route=catalog/information/update&token=be54d82da3beb8855eb80bc49a4b28a4&information_id=16
)
)
)
我希望表格看起来像这样:
+-------+------------+--------+
| Title | Sort order | Action |
+-------+------------+--------+