Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Create Multiple tables from multidimensional array
    text
    copied!<p>I have array like this:</p> <pre><code>{"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"}]} </code></pre> <hr> <pre><code>Array ( [0] =&gt; Array ( [0] =&gt; Array ( [1] =&gt; stdClass Object ( [column] =&gt; 0 [name] =&gt; U2 UB [row] =&gt; 0 [zIndex] =&gt; 1 ) [0] =&gt; stdClass Object ( [column] =&gt; 0 [name] =&gt; L2 LB [row] =&gt; 0 [zIndex] =&gt; 0 ) ) [8] =&gt; Array ( [1] =&gt; stdClass Object ( [column] =&gt; 8 [name] =&gt; U10 UB [row] =&gt; 0 [zIndex] =&gt; 1 ) [0] =&gt; stdClass Object ( [column] =&gt; 8 [name] =&gt; L10 LB [row] =&gt; 0 [zIndex] =&gt; 0 ) ) [6] =&gt; Array ( [1] =&gt; stdClass Object ( [column] =&gt; 6 [name] =&gt; U8 UB [row] =&gt; 0 [zIndex] =&gt; 1 ) [0] =&gt; stdClass Object ( [column] =&gt; 6 [name] =&gt; L8 LB [row] =&gt; 0 [zIndex] =&gt; 0 ) ) [4] =&gt; Array ( [1] =&gt; stdClass Object ( [column] =&gt; 4 [name] =&gt; U6 UB [row] =&gt; 0 [zIndex] =&gt; 1 ) [0] =&gt; stdClass Object ( [column] =&gt; 4 [name] =&gt; L6 LB [row] =&gt; 0 [zIndex] =&gt; 0 ) ) [2] =&gt; Array ( [1] =&gt; stdClass Object ( [column] =&gt; 2 [name] =&gt; U4 UB [row] =&gt; 0 [zIndex] =&gt; 1 ) [0] =&gt; stdClass Object ( [column] =&gt; 2 [name] =&gt; L4 LB [row] =&gt; 0 [zIndex] =&gt; 0 ) ) ) [1] =&gt; Array ( [0] =&gt; Array ( [0] =&gt; stdClass Object ( [column] =&gt; 0 [name] =&gt; L1 LB [row] =&gt; 1 [zIndex] =&gt; 0 ) [1] =&gt; stdClass Object ( [column] =&gt; 0 [name] =&gt; U1 UB [row] =&gt; 1 [zIndex] =&gt; 1 ) ) [8] =&gt; Array ( [1] =&gt; stdClass Object ( [column] =&gt; 8 [name] =&gt; U9 UB [row] =&gt; 1 [zIndex] =&gt; 1 ) [0] =&gt; stdClass Object ( [column] =&gt; 8 [name] =&gt; L9 LB [row] =&gt; 1 [zIndex] =&gt; 0 ) ) [6] =&gt; Array ( [1] =&gt; stdClass Object ( [column] =&gt; 6 [name] =&gt; U7 UB [row] =&gt; 1 [zIndex] =&gt; 1 ) [0] =&gt; stdClass Object ( [column] =&gt; 6 [name] =&gt; L7 LB [row] =&gt; 1 [zIndex] =&gt; 0 ) ) [4] =&gt; Array ( [1] =&gt; stdClass Object ( [column] =&gt; 4 [name] =&gt; U5 UB [row] =&gt; 1 [zIndex] =&gt; 1 ) [0] =&gt; stdClass Object ( [column] =&gt; 4 [name] =&gt; L5 LB [row] =&gt; 1 [zIndex] =&gt; 0 ) ) [2] =&gt; Array ( [1] =&gt; stdClass Object ( [column] =&gt; 2 [name] =&gt; U3 UB [row] =&gt; 1 [zIndex] =&gt; 1 ) [0] =&gt; stdClass Object ( [column] =&gt; 2 [name] =&gt; L3 LB [row] =&gt; 1 [zIndex] =&gt; 0 ) ) ) [3] =&gt; Array ( [8] =&gt; Array ( [0] =&gt; stdClass Object ( [column] =&gt; 8 [name] =&gt; SL5 LB [row] =&gt; 3 [zIndex] =&gt; 0 ) [1] =&gt; stdClass Object ( [column] =&gt; 8 [name] =&gt; SU5 UB [row] =&gt; 3 [zIndex] =&gt; 1 ) ) [6] =&gt; Array ( [0] =&gt; stdClass Object ( [column] =&gt; 6 [name] =&gt; SL4 LB [row] =&gt; 3 [zIndex] =&gt; 0 ) [1] =&gt; stdClass Object ( [column] =&gt; 6 [name] =&gt; SU4 UB [row] =&gt; 3 [zIndex] =&gt; 1 ) ) [4] =&gt; Array ( [0] =&gt; stdClass Object ( [column] =&gt; 4 [name] =&gt; SL3 LB [row] =&gt; 3 [zIndex] =&gt; 0 ) [1] =&gt; stdClass Object ( [column] =&gt; 4 [name] =&gt; SU3 UB [row] =&gt; 3 [zIndex] =&gt; 1 ) ) [2] =&gt; Array ( [0] =&gt; stdClass Object ( [column] =&gt; 2 [name] =&gt; SL2 LB [row] =&gt; 3 [zIndex] =&gt; 0 ) [1] =&gt; stdClass Object ( [column] =&gt; 2 [name] =&gt; SU2 UB [row] =&gt; 3 [zIndex] =&gt; 1 ) ) [0] =&gt; Array ( [0] =&gt; stdClass Object ( [column] =&gt; 0 [name] =&gt; SL1 LB [row] =&gt; 3 [zIndex] =&gt; 0 ) [1] =&gt; stdClass Object ( [column] =&gt; 0 [name] =&gt; SU1 UB [row] =&gt; 3 [zIndex] =&gt; 1 ) ) ) ) </code></pre> <p>I try to create TWO tables from the above array and got result as :<pre>L2 LB<br>U2 UB<br>L4 LB<br>U4 UB<br>L6 LB<br>U6 UB<br>L8 LB<br>U8 UB<br>L10 LB<br>U10 UB<br>L1 LB<br>U1 UB<br>L3 LB<br>U3 UB<br>L5 LB<br>U5 UB<br>L7 LB<br>U7 UB<br>L9 LB<br>U9 UB<br>SL1 LB<br>SU1 UB<br>SL2 LB<br>SU2 UB<br>SL3 LB<br>SU3 UB<br>SL4 LB<br>SU4 UB<br>SL5 LB<br>SU5 UB<br></pre></p> <p>I tried with this>>>></p> <pre><code>foreach ($output_sub1 as $output_sub11) { ksort($output_sub11); echo '&lt;table border="1"&gt;'; foreach ($output_sub11 as $output_sub12) { echo '&lt;tr&gt;'; //print_r($output_sub12); ksort($output_sub12); foreach($output_sub12 as $row_sub1 =&gt; $columns_sub1) { echo '&lt;td&gt;'; echo $columns_sub1-&gt;name."&lt;br&gt;"; echo '&lt;/td&gt;'; } echo '&lt;/tr&gt;'; } echo '&lt;/table&gt;'; } </code></pre> <p>But my desired results should be like this >>></p> <p><b>Table # 1 : </b></p> <pre>3U UB |6U UB |9U UB |12U UB |15U UB |18U UB |<br>2U UB |5U UB |8U UB |11U UB |14U UB |17U UB |<br>1U UB |4U UB |7U UB |10U UB |13U UB |16U UB |</pre> <p><b>Table # 2 : </b></p> <pre>3L LB |6L LB |9L LB |12L LB |15L LB |18L LB |<br>2L LB |5L LB |8L LB |11L LB |14L LB |17L LB |<br>1L LB |4L LB |7L LB |10L LB |13L LB |16L LB |</pre> <p>Can anyone say how can i traverse the loop to create like above table?<br> 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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload