私はこのような配列を持っています:
{"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
)
)
)
)
上記の配列から 2 つのテーブルを作成しようとすると、次のような結果が得られました。
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
これでやってみた>>>>
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>';
}
しかし、私の望ましい結果は次のようになるはずです >>>
表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 としてグループ化される必要があります。