Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php数组中的Html表_Php_Html_Arrays - Fatal编程技术网

php数组中的Html表

php数组中的Html表,php,html,arrays,Php,Html,Arrays,我有这个数组,有人能帮我把它放到html表中吗?可撕裂头应为名称、类别、起始日期和创建日期 Array ( [0] => Array ( [remoteid] => 4 [cat_id] => 1 [cat_name] => Miscellaneous [cat_description] => [sortorder] =&

我有这个数组,有人能帮我把它放到html表中吗?可撕裂头应为名称、类别、起始日期和创建日期

Array
(
    [0] => Array
        (
            [remoteid] => 4
            [cat_id] => 1
            [cat_name] => Miscellaneous
            [cat_description] => 
            [sortorder] => 10001
            [fullname] => Test3
            [shortname] => tst23
            [idnumber] => 
            [summary] => 
            [startdate] => 1426629600
            [created] => 1426609147
            [modified] => 1426609147
            [self_enrolment] => 0
            [enroled] => 0
            [in_enrol_date] => 1
            [guest] => 0
        )

    [1] => Array
        (
            [remoteid] => 3
            [cat_id] => 1
            [cat_name] => Miscellaneous
            [cat_description] => 
            [sortorder] => 10002
            [fullname] => Test2
            [shortname] => tst2
            [idnumber] => 
            [summary] => 
            [startdate] => 1426629600
            [created] => 1426609034
            [modified] => 1426609034
            [self_enrolment] => 0
            [enroled] => 0
            [in_enrol_date] => 1
            [guest] => 0
        )

    [2] => Array
        (
            [remoteid] => 2
            [cat_id] => 1
            [cat_name] => Miscellaneous
            [cat_description] => 
            [sortorder] => 10003
            [fullname] => Test
            [shortname] => tst
            [idnumber] => 
            [summary] => 
            [startdate] => 1426629600
            [created] => 1426602753
            [modified] => 1426602753
            [self_enrolment] => 0
            [enroled] => 0
            [in_enrol_date] => 1
            [guest] => 0
        )

)

请为此阵列尝试以下操作:

echo "<table>";
$i = 0;
foreach($array as $row){
    echo " <tr>";
    if ($i == 0)
        foreach ($row as $name=>$value)
            echo "<th>$name</th>";
    foreach ($row as $name=>$value)
        echo "<td>$value</td>";
    echo "</tr>"; 
    $i++;
}
echo "</table>";
尝试使用简单的foreach循环,但根据需要更改数组。我添加了一个演示阵列

$array=array(
             array('fullname'=>'Test2','category'=>'test1','startdate'=>1426629600,'created'=>1426609034),
             array('fullname'=>'Test3','category'=>'test3','startdate'=>14266234300,'created'=>2323232)
            );
?>
<table>
    <thead>
    <tr>
        <th class="name">Name</th>
        <th class="category">Category</th>
        <th class="startdate">Start Date</th>
        <th class="created">Created</th>
    </tr>
    </thead>
    <tbody>
    <?php foreach($array as $key=>$values){
    ?>
    <tr>

        <td><?php echo $values['fullname']; ?></td>
        <td><?php echo $values['category']; ?></td>
        <td><?php echo $values['startdate']; ?></td>
        <td><?php echo $values['created']; ?></td>

   </tr>
    <?php }?>
    </tbody>
</table>

只需从一些代码开始!然后我们将修复它,并显示错误在哪里问题是我不知道如何做,我需要一个学校的项目,然后你可能想从学习PHP开始basics@BalasoiuAndreiStackoverflow不适用于为您完成项目。如果你已经正确地完成了你的研究,并且陷入困境,那么你可以问你的问题。我开始研究php foreach循环,如果需要的话,我会带着问题回来。谢谢大家:@BalasoiuAndrei你们是怎么找到这个阵列的?听起来不对,它看起来像是一个阵列的输出
$array=array(
             array('fullname'=>'Test2','category'=>'test1','startdate'=>1426629600,'created'=>1426609034),
             array('fullname'=>'Test3','category'=>'test3','startdate'=>14266234300,'created'=>2323232)
            );
?>
<table>
    <thead>
    <tr>
        <th class="name">Name</th>
        <th class="category">Category</th>
        <th class="startdate">Start Date</th>
        <th class="created">Created</th>
    </tr>
    </thead>
    <tbody>
    <?php foreach($array as $key=>$values){
    ?>
    <tr>

        <td><?php echo $values['fullname']; ?></td>
        <td><?php echo $values['category']; ?></td>
        <td><?php echo $values['startdate']; ?></td>
        <td><?php echo $values['created']; ?></td>

   </tr>
    <?php }?>
    </tbody>
</table>