Home > Backend Development > PHP Tutorial > 数组 - ThinkPHP数据结构的组织输出问题,求tp大拿帮忙,不胜感激!

数组 - ThinkPHP数据结构的组织输出问题,求tp大拿帮忙,不胜感激!

WBOY
Release: 2016-06-06 20:11:17
Original
898 people have browsed it

小弟纠结这个问题已经一天有余,实在是脑力不够,求tp大拿帮忙,不胜感激!问题如下:
使用tp的过程中,取出如下数据结构,想在模版页面输出,输出的时候需要按照orde_menu_date和orde_dinner_time为第一维,orde_sn为第二维,orde_dish_id和orde_sauce_id为第三维来循环输出,请问如何重新组织数据结构?

数据结构如下:
array (size=6)
0 =>

<code>array (size=9)
  'orde_id' => string '154' (length=3)
  'orde_sn' => string 'aaaa' (length=12)
  'orde_menu_date' => string '2016414' (length=10)
  'orde_dinner_time' => string '0' (length=1)
  'orde_status' => string '0' (length=1)
  'orde_dish_id' => string '12' (length=2)
  'orde_sauc_id' => string '2' (length=1)
  'dish_name' => string '地中海水果沙拉' (length=21)
  'sauc_name' => string '北京甜面酱' (length=15)</code>
Copy after login
Copy after login

1 =>

<code>array (size=9)
  'orde_id' => string '155' (length=3)
  'orde_sn' => string 'bbbbb' (length=32)
  'orde_menu_date' => string '2016414' (length=10)
  'orde_dinner_time' => string '0' (length=1)
  'orde_status' => string '0' (length=1)
  'orde_dish_id' => string '12' (length=2)
  'orde_sauc_id' => string '2' (length=1)
  'dish_name' => string '地中海水果沙拉' (length=21)
  'sauc_name' => string '北京甜面酱' (length=15)</code>
Copy after login
Copy after login

2 =>

<code>array (size=9)
  'orde_id' => string '149' (length=3)
  'orde_sn' => string 'aaaaa' (length=32)
  'orde_menu_date' => string '2016414' (length=10)
  'orde_dinner_time' => string '1' (length=1)
  'orde_status' => string '0' (length=1)
  'orde_dish_id' => string '9' (length=1)
  'orde_sauc_id' => string '0' (length=1)
  'dish_name' => string '红烧肉' (length=9)
  'sauc_name' => null</code>
Copy after login
Copy after login

3 =>

<code>array (size=9)
  'orde_id' => string '151' (length=3)
  'orde_sn' => string 'aaaaa' (length=32)
  'orde_menu_date' => string '2016415' (length=10)
  'orde_dinner_time' => string '0' (length=1)
  'orde_status' => string '0' (length=1)
  'orde_dish_id' => string '1' (length=1)
  'orde_sauc_id' => string '0' (length=1)
  'dish_name' => string '鱼香肉丝' (length=12)
  'sauc_name' => null</code>
Copy after login
Copy after login

4 =>

<code>array (size=9)
  'orde_id' => string '153' (length=3)
  'orde_sn' => string 'aaaaa' (length=32)
  'orde_menu_date' => string '2016415' (length=10)
  'orde_dinner_time' => string '0' (length=1)
  'orde_status' => string '0' (length=1)
  'orde_dish_id' => string '1' (length=1)
  'orde_sauc_id' => string '0' (length=1)
  'dish_name' => string '鱼香肉丝' (length=12)
  'sauc_name' => null</code>
Copy after login
Copy after login

5 =>

<code>array (size=9)
  'orde_id' => string '152' (length=3)
  'orde_sn' => string 'aaaaa' (length=32)
  'orde_menu_date' => string '2016415' (length=10)
  'orde_dinner_time' => string '0' (length=1)
  'orde_status' => string '0' (length=1)
  'orde_dish_id' => string '13' (length=2)
  'orde_sauc_id' => string '0' (length=1)
  'dish_name' => string '羊肉泡馍' (length=12)
  'sauc_name' => null
</code>
Copy after login
Copy after login

输出示意如下:

2016-4-14 午餐
单号:aaaaa
地中海水果沙拉(北京甜面酱) x1

单号:bbbbb
地中海水果沙拉(北京甜面酱) x1

2016-4-14 晚餐
单号:aaaaa
红烧肉 x1

2016-4-15 午餐
单号:aaaaa
鱼香肉丝 x2
羊肉泡馍 x1

回复内容:

小弟纠结这个问题已经一天有余,实在是脑力不够,求tp大拿帮忙,不胜感激!问题如下:
使用tp的过程中,取出如下数据结构,想在模版页面输出,输出的时候需要按照orde_menu_date和orde_dinner_time为第一维,orde_sn为第二维,orde_dish_id和orde_sauce_id为第三维来循环输出,请问如何重新组织数据结构?

数据结构如下:
array (size=6)
0 =>

<code>array (size=9)
  'orde_id' => string '154' (length=3)
  'orde_sn' => string 'aaaa' (length=12)
  'orde_menu_date' => string '2016414' (length=10)
  'orde_dinner_time' => string '0' (length=1)
  'orde_status' => string '0' (length=1)
  'orde_dish_id' => string '12' (length=2)
  'orde_sauc_id' => string '2' (length=1)
  'dish_name' => string '地中海水果沙拉' (length=21)
  'sauc_name' => string '北京甜面酱' (length=15)</code>
Copy after login
Copy after login

1 =>

<code>array (size=9)
  'orde_id' => string '155' (length=3)
  'orde_sn' => string 'bbbbb' (length=32)
  'orde_menu_date' => string '2016414' (length=10)
  'orde_dinner_time' => string '0' (length=1)
  'orde_status' => string '0' (length=1)
  'orde_dish_id' => string '12' (length=2)
  'orde_sauc_id' => string '2' (length=1)
  'dish_name' => string '地中海水果沙拉' (length=21)
  'sauc_name' => string '北京甜面酱' (length=15)</code>
Copy after login
Copy after login

2 =>

<code>array (size=9)
  'orde_id' => string '149' (length=3)
  'orde_sn' => string 'aaaaa' (length=32)
  'orde_menu_date' => string '2016414' (length=10)
  'orde_dinner_time' => string '1' (length=1)
  'orde_status' => string '0' (length=1)
  'orde_dish_id' => string '9' (length=1)
  'orde_sauc_id' => string '0' (length=1)
  'dish_name' => string '红烧肉' (length=9)
  'sauc_name' => null</code>
Copy after login
Copy after login

3 =>

<code>array (size=9)
  'orde_id' => string '151' (length=3)
  'orde_sn' => string 'aaaaa' (length=32)
  'orde_menu_date' => string '2016415' (length=10)
  'orde_dinner_time' => string '0' (length=1)
  'orde_status' => string '0' (length=1)
  'orde_dish_id' => string '1' (length=1)
  'orde_sauc_id' => string '0' (length=1)
  'dish_name' => string '鱼香肉丝' (length=12)
  'sauc_name' => null</code>
Copy after login
Copy after login

4 =>

<code>array (size=9)
  'orde_id' => string '153' (length=3)
  'orde_sn' => string 'aaaaa' (length=32)
  'orde_menu_date' => string '2016415' (length=10)
  'orde_dinner_time' => string '0' (length=1)
  'orde_status' => string '0' (length=1)
  'orde_dish_id' => string '1' (length=1)
  'orde_sauc_id' => string '0' (length=1)
  'dish_name' => string '鱼香肉丝' (length=12)
  'sauc_name' => null</code>
Copy after login
Copy after login

5 =>

<code>array (size=9)
  'orde_id' => string '152' (length=3)
  'orde_sn' => string 'aaaaa' (length=32)
  'orde_menu_date' => string '2016415' (length=10)
  'orde_dinner_time' => string '0' (length=1)
  'orde_status' => string '0' (length=1)
  'orde_dish_id' => string '13' (length=2)
  'orde_sauc_id' => string '0' (length=1)
  'dish_name' => string '羊肉泡馍' (length=12)
  'sauc_name' => null
</code>
Copy after login
Copy after login

输出示意如下:

2016-4-14 午餐
单号:aaaaa
地中海水果沙拉(北京甜面酱) x1

单号:bbbbb
地中海水果沙拉(北京甜面酱) x1

2016-4-14 晚餐
单号:aaaaa
红烧肉 x1

2016-4-15 午餐
单号:aaaaa
鱼香肉丝 x2
羊肉泡馍 x1

楼主是想把相同日期且相同产品的订单分成组是吧?这样的话就要循环查询出来的订单,重新构建数组了。


试了一下,不知道是不是你想要的。 (代码有点low 见谅)

<code>$arr = 你的数据;
$data = array();
$a = 0;
$data[$a]['orde_sn'][0] = $arr[0]['orde_sn'];
$data[$a]['orde_menu_date'] = $arr[0]['orde_menu_date'];
$data[$a]['dish_name'][0] = $arr[0]['dish_name'];
$data[$a]['sauc_name'][0] = $arr[0]['sauc_name'];
for($i=1; $i<count if></count></code>
Copy after login

分组......

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template