php遍历二维数组

数据模板

Array
(
    [0] => Array
        (
            [uid] => 1
            [username] => admin
            [password] => e10adc3949ba59abbe56e057f20f883e
            [sex] => 男
            [email] => admin@gxusb.com
            [phonenum] => 10086110000
            [createtime] => 1600853499
        )

    [1] => Array
        (
            [uid] => 2
            [username] => user
            [password] => e10adc3949ba59abbe56e057f20f883e
            [sex] => 女
            [email] => user@gxusb.com
            [phonenum] => 10086110000
            [createtime] => 1600853606
        )

    [2] => Array
        (
            [uid] => 3
            [username] => 123456
            [password] => e10adc3949ba59abbe56e057f20f883e
            [sex] => 保密
            [email] => 123456@qq.com
            [phonenum] => 12345069454
            [createtime] => 1601005377
        )

    [3] => Array
        (
            [uid] => 4
            [username] => gxggxl
            [password] => 25d55ad283aa400af464c76d713c07ad
            [sex] => 男
            [email] => gxggxl@qq.com
            [phonenum] => 10000100861
            [createtime] => 1601060681
        )

    [4] => Array
        (
            [uid] => 5
            [username] => user1
            [password] => e807f1fcf82d132f9bb018ca6738a19f
            [sex] => 女
            [email] => user1@gxusb.com
            [phonenum] => 12345678900
            [createtime] => 1601211185
        )

)

for循环遍历二维数组

for($i=0; $i <count($rows) ; $i++){
    echo '<tr>';
    echo '<td>'.$rows[$i]["uid"].'</td>';
    echo '<td>'.$rows[$i]["username"].'</td>';
    echo '<td>'.$rows[$i]["sex"].'</td>';
    echo '<td>'.$rows[$i]["email"].'</td>';
    echo '<td>'.$rows[$i]["phonenum"].'</td>';
    echo '<td>'.$rows[$i]["createtime"].'</td>';
    echo '</tr>';
}

效果

uidusernamesexemailphonenumcreatetime
1adminadmin@gxusb.com100861100001600853499
2useruser@gxusb.com100861100001600853606
3123456保密123456@qq.com123450694541601005377
4gxggxlgxggxl@qq.com100001008611601060681
5user1user1@gxusb.com123456789001601211185

count函数定义和用法

count() 函数返回数组中元素的数目。

count函数语法

count(array,mode);
参数描述
array必需。规定数组。
mode可选。规定模式。
可能的值:
0 - 默认。不对多维数组中的所有元素进行计数。
1 - 递归地计数数组中元素的数目(计算多维数组中的所有元素)