PHP创建从多维数组多个表 [英] PHP Create Multiple tables from multidimensional array

查看:117
本文介绍了PHP创建从多维数组多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数组是这样的:

{"seats":[{"column":"8","fare":"995.0","name":"U10 UB","row":"0","zIndex":"1"},
{"column":"8","fare":"995.0","name":"U9 UB","row":"1","zIndex":"1"},
{"column":"8","fare":"995.0","name":"L10 LB","row":"0","zIndex":"0"},
{"column":"8","fare":"995.0","name":"L9 LB","row":"1","zIndex":"0"},
{"column":"8","fare":"995.0","name":"SL5 LB","row":"3","zIndex":"0"},
{"column":"8","fare":"995.0","name":"SU5 UB","row":"3","zIndex":"1"},
{"column":"6","fare":"995.0","name":"U8 UB","row":"0","zIndex":"1"},
{"column":"6","fare":"995.0","name":"U7 UB","row":"1","zIndex":"1"},
{"column":"6","fare":"995.0","name":"L8 LB","row":"0","zIndex":"0"},
{"column":"6","fare":"995.0","name":"L7 LB","row":"1","zIndex":"0"},
{"column":"6","fare":"995.0","name":"SL4 LB","row":"3","zIndex":"0"},
{"column":"6","fare":"995.0","name":"SU4 UB","row":"3","zIndex":"1"},
{"column":"4","fare":"995.0","name":"U6 UB","row":"0","zIndex":"1"},
{"column":"4","fare":"995.0","name":"U5 UB","row":"1","zIndex":"1"},
{"column":"4","fare":"995.0","name":"L6 LB","row":"0","zIndex":"0"},
{"column":"4","fare":"995.0","name":"L5 LB","row":"1","zIndex":"0"},
{"column":"4","fare":"995.0","name":"SL3 LB","row":"3","zIndex":"0"},
{"column":"4","fare":"995.0","name":"SU3 UB","row":"3","zIndex":"1"},
{"available":"false","column":"2","fare":"995.0","name":"U4 UB","row":"0","zIndex":"1"},
{"available":"false","column":"2","fare":"995.0","name":"U3 UB","row":"1","zIndex":"1"},
{"available":"false","column":"2","fare":"995.0","name":"L4 LB","row":"0","zIndex":"0"},
{"available":"false","column":"2","fare":"995.0","name":"L3 LB","row":"1","zIndex":"0"},
{"available":"false","column":"2","fare":"995.0","name":"SL2 LB","row":"3","zIndex":"0"},
{"available":"false","column":"2","fare":"995.0","name":"SU2 UB","row":"3","zIndex":"1"},
{"available":"false","column":"0","fare":"995.0","name":"U2 UB","row":"0","zIndex":"1"},
{"available":"false","column":"0","fare":"995.0","name":"U1 UB","row":"1","zIndex":"1"},
{"available":"false","column":"0","fare":"995.0","name":"L2 LB","row":"0","zIndex":"0"},
{"available":"false","column":"0","fare":"995.0","name":"L1 LB","row":"1","zIndex":"0"},
{"available":"false","column":"0","fare":"995.0","name":"SL1 LB","row":"3","zIndex":"0"},
{"available":"false","column":"0","fare":"995.0","name":"SU1 UB","row":"3","zIndex":"1"}]}


Array (
      [0] => Array (
        [0] => Array (
            [1] => stdClass Object (
                [column] => 0
                [name] => U2 UB
                [row] => 0
                [zIndex] => 1
              )
            [0] => stdClass Object (
                [column] => 0
                [name] => L2 LB
                [row] => 0
                [zIndex] => 0
              )
          )
        [8] => Array (
            [1] => stdClass Object (
                [column] => 8
                [name] => U10 UB
                [row] => 0
                [zIndex] => 1
              )
            [0] => stdClass Object (
                [column] => 8
                [name] => L10 LB
                [row] => 0
                [zIndex] => 0
              )
          )
        [6] => Array (
            [1] => stdClass Object (
                [column] => 6
                [name] => U8 UB
                [row] => 0
                [zIndex] => 1
              )
            [0] => stdClass Object (
                [column] => 6
                [name] => L8 LB
                [row] => 0
                [zIndex] => 0
              )
          )
        [4] => Array (
            [1] => stdClass Object (
                [column] => 4
                [name] => U6 UB
                [row] => 0
                [zIndex] => 1
              )
            [0] => stdClass Object (
                [column] => 4
                [name] => L6 LB
                [row] => 0
                [zIndex] => 0
              )
          )
        [2] => Array (
            [1] => stdClass Object (
                [column] => 2
                [name] => U4 UB
                [row] => 0
                [zIndex] => 1
              )
            [0] => stdClass Object (
                [column] => 2
                [name] => L4 LB
                [row] => 0
                [zIndex] => 0
              )
          )
      )
      [1] => Array (
        [0] => Array (
            [0] => stdClass Object (
                [column] => 0
                [name] => L1 LB
                [row] => 1
                [zIndex] => 0
              )
            [1] => stdClass Object (
                [column] => 0
                [name] => U1 UB
                [row] => 1
                [zIndex] => 1
              )
          )
        [8] => Array (
            [1] => stdClass Object (
                [column] => 8
                [name] => U9 UB
                [row] => 1
                [zIndex] => 1
              )
            [0] => stdClass Object (
                [column] => 8
                [name] => L9 LB
                [row] => 1
                [zIndex] => 0
              )
          )
        [6] => Array (
            [1] => stdClass Object (
                [column] => 6
                [name] => U7 UB
                [row] => 1
                [zIndex] => 1
              )
            [0] => stdClass Object (
                [column] => 6
                [name] => L7 LB
                [row] => 1
                [zIndex] => 0
              )
          )
        [4] => Array (
            [1] => stdClass Object (
                [column] => 4
                [name] => U5 UB
                [row] => 1
                [zIndex] => 1
              )
            [0] => stdClass Object (
                [column] => 4
                [name] => L5 LB
                [row] => 1
                [zIndex] => 0
              )
          )
        [2] => Array (
            [1] => stdClass Object (
                [column] => 2
                [name] => U3 UB
                [row] => 1
                [zIndex] => 1
              )
            [0] => stdClass Object (
                [column] => 2
                [name] => L3 LB
                [row] => 1
                [zIndex] => 0
              )
          )
      )
      [3] => Array (
        [8] => Array (
            [0] => stdClass Object (
                [column] => 8
                [name] => SL5 LB
                [row] => 3
                [zIndex] => 0
              )
            [1] => stdClass Object (
                [column] => 8
                [name] => SU5 UB
                [row] => 3
                [zIndex] => 1
              )
          )
        [6] => Array (
            [0] => stdClass Object (
                [column] => 6
                [name] => SL4 LB
                [row] => 3
                [zIndex] => 0
              )
            [1] => stdClass Object (
                [column] => 6
                [name] => SU4 UB
                [row] => 3
                [zIndex] => 1
              )
          )
        [4] => Array (
            [0] => stdClass Object (
                [column] => 4
                [name] => SL3 LB
                [row] => 3
                [zIndex] => 0
              )
            [1] => stdClass Object (
                [column] => 4
                [name] => SU3 UB
                [row] => 3
                [zIndex] => 1
              )
          )
        [2] => Array (
            [0] => stdClass Object (
                [column] => 2
                [name] => SL2 LB
                [row] => 3
                [zIndex] => 0
              )
            [1] => stdClass Object (
                [column] => 2
                [name] => SU2 UB
                [row] => 3
                [zIndex] => 1
              )
          )
        [0] => Array (
            [0] => stdClass Object (
                [column] => 0
                [name] => SL1 LB
                [row] => 3
                [zIndex] => 0
              )
            [1] => stdClass Object (
                [column] => 0
                [name] => SU1 UB
                [row] => 3
                [zIndex] => 1
              )
          )
      )
    )

我尝试从上述阵列创建两个表,得到了结果为:

I try to create TWO tables from the above array and got result as :

L2 LB
U2 UB
L4 LB
U4 UB
L6 LB
U6 UB
L8 LB
U8 UB
L10 LB
U10 UB
L1 LB
U1 UB
L3 LB
U3 UB
L5 LB
U5 UB
L7 LB
U7 UB
L9 LB
U9 UB
SL1 LB
SU1 UB
SL2 LB
SU2 UB
SL3 LB
SU3 UB
SL4 LB
SU4 UB
SL5 LB
SU5 UB

我试着用这个>>>>

I tried with this>>>>

foreach ($output_sub1 as $output_sub11) {
         ksort($output_sub11);
         echo '<table border="1">'; 
        foreach ($output_sub11 as $output_sub12) {
          echo '<tr>';
         //print_r($output_sub12);  
         ksort($output_sub12);        

        foreach($output_sub12 as $row_sub1 => $columns_sub1) {
             echo '<td>';
                echo  $columns_sub1->name."<br>";                 
             echo '</td>';    
                }
        echo '</tr>';
            }
        echo '</table>';
    }

但我想要的结果应该是这样>>>

But my desired results should be like this >>>

表1:

3U UB |6U UB |9U UB |12U UB |15U UB |18U UB |
2U UB |5U UB |8U UB |11U UB |14U UB |17U UB |
1U UB |4U UB |7U UB |10U UB |13U UB |16U UB |

表2:

3L LB |6L LB |9L LB |12L LB |15L LB |18L LB |
2L LB |5L LB |8L LB |11L LB |14L LB |17L LB |
1L LB |4L LB |7L LB |10L LB |13L LB |16L LB |

任何人都可以说我该怎么遍历循环创建如上表?结果
注意:阵列包含zIndex的值作为0和1。因此所有的zIndex的值0应当如表#1进行分组和所有zIndex的值1应该被分组为表#2

Can anyone say how can i traverse the loop to create like above table?
Note : Array contains zIndex values as 0 and 1. So all the zIndex value 0 should be grouped as table #1 and all the zIndex Value 1 should be grouped as table#2.

推荐答案

我已经发布了code在这里..

I have posted the code here..

http://jaiphp.blogspot.in/

这是否帮助?

这篇关于PHP创建从多维数组多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆