动态设置为表头的PHP数组键
我将一组序列化的动态设置为表头的PHP数组键,php,arrays,Php,Arrays,我将一组序列化的$\u POST数据存储到我的数据库中。获取并取消序列化后,数据表示为如下数组: Array ( [size] => 1359sf [buyfor] => Investment [budget] => 401,000-500,000 [fullname] => Chris Mark [age] => 36 [semail] => mark.c@hotmail.com [phone] =&g
$\u POST
数据存储到我的数据库中。获取并取消序列化后,数据表示为如下数组:
Array
(
[size] => 1359sf
[buyfor] => Investment
[budget] => 401,000-500,000
[fullname] => Chris Mark
[age] => 36
[semail] => mark.c@hotmail.com
[phone] => 6781822333
)
这些数组键是否可以动态设置为
,如下所示:
<table>
<thead>
<tr>
<th>size</th>
<th>buyfor</th>
<th>budget</th>
<th>fullname</th>
</tr>
</thead>
..looping recordset..
</table>
我只想选择size
、buyfor
和budget
设置为
//固定收割台
第1栏
第2栏
//动态标题
大小
买断
预算
..循环记录集。。
您可以使用函数获取密钥
echo';
回声内爆(“”,$keys);
回声';
据我所知,您希望构建表的列标题,它将表示未序列化数组中的数据。如果是这种情况,则可以尝试如下循环槽阵列:
<table>
<thead>
<tr>
<?php
foreach($array as $key=>$value) {
echo "<th>".$key."</th>";
}
?>
</tr>
</table>
<table>
<thead>
<tr>
//fixed header
<th>column 1</th>
<th>column 2</th>
//dynamic header
<th>size</th>
<th>buyfor</th>
<th>budget</th>
</tr>
</thead>
..looping recordset..
</table>
echo '<tr><th>';
echo implode('</th><th>', $keys);
echo '</th></tr>';
<table>
<thead>
<tr>
<?php
foreach($array as $key=>$value) {
echo "<th>".$key."</th>";
}
?>
</tr>
</table>