如何从PHP数组动态创建tr td [英] How to create dynamically tr td from PHP array
本文介绍了如何从PHP数组动态创建tr td的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
How to create dynamically tr td from below array In below array first node comes in first [2] inner nodes comes in next cell like [2][15]. The inner node will be any thing it will be (1,2,3,4,5....n number of count).
Array
(
[2] => Array
(
[2] => Array
(
[0] => 11
[1] => 12
[2] => 13
)
[15] => Array
(
[0] => 23
[1] => 24
)
)
[3] => Array
(
[2] => Array
(
[0] => 11
[1] => 12
[2] => 13
)
[15] => Array
(
[0] => 23
[1] => 24
)
)
)
the out put of the above array is :
<table class="table table-striped table-responsive">
<tbody>
<tr>
<th>[2]</th>
<th>[2]</th>
<th>[15]</th>
</tr>
<tr>
<td>[2]</td>
<td>11</td>
<td>23</td>
</tr>
<tr>
<td>[2]</td>
<td>12</td>
<td>23</td>
</tr>
<tr>
<td>[2]</td>
<td>13</td>
<td>24</td>
</tr>
<tr>
<td>[2]</td>
<td>11</td>
<td>24</td>
</tr>
<tr>
<td>[2]</td>
<td>12</td>
<td>14</td>
</tr>
<tr>
<td>[2]</td>
<td>13</td>
<td>24</td>
</tr>
<tr>
<td>[3]</td>
<td>11</td>
<td>23</td>
</tr>
<tr>
<td>[3]</td>
<td>12</td>
<td>13</td>
</tr>
<tr>
<td>[3]</td>
<td>13</td>
<td>24</td>
</tr>
<tr>
<td>[3]</td>
<td>11</td>
<td>24</td>
</tr>
<tr>
<td>[3]</td>
<td>12</td>
<td>14</td>
</tr>
<tr>
<td>[3]</td>
<td>13</td>
<td>24</td>
</tr>
</tbody>
</table>
The inner td will be generate dynamically display inner node value according to its key.
我尝试了什么:
如何从下面的数组动态创建tr td在下面的数组中第一个节点来了在第一个[2]内部节点进入下一个单元格,如[2] [15]。内部节点将是任何东西(1,2,3,4,5 .... n计数)。
What I have tried:
How to create dynamically tr td from below array In below array first node comes in first [2] inner nodes comes in next cell like [2][15]. The inner node will be any thing it will be (1,2,3,4,5....n number of count).
推荐答案
这是一个PHP的多维关联数组。解决这个问题的第一步始终是如何在各个维度(部门)读取密钥及其相关值。为此,您可以使用 PHP 5阵列 [ ^ ]
在您的情况下,有三个级别,运行此代码:
This is a multi-dimensional associative array of PHP. The first step to approach such a problem is always about how to read the keys and their associated values at the respective dimensions (dept). For that, you can use PHP 5 Arrays[^]
In your case, there are three levels, run this code:
<?php
multi_assoc_array = array(2=> array(
2=> array( 0=>11,1=>12,2=>13),
15=>数组(0=>23 ,1=>24)
),
3=>数组(
2=>数组(0=>11) ,1=>12,2=>13),
15=>数组(0=>23,1=> ;24)
)
);
multi_assoc_array = array("2"=>array( "2"=>array("0"=>"11", "1"=>"12", "2"=>"13"), "15"=>array("0"=>"23", "1"=>"24") ), "3"=>array( "2"=>array("0"=>"11", "1"=>"12", "2"=>"13"), "15"=>array("0"=>"23", "1"=>"24") ) );
tab =& nbsp;& nbsp;& nbsp;& nbsp; &安培; NBSP;;
foreach(
tab=" "; foreach(
这篇关于如何从PHP数组动态创建tr td的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文