doutizhou5312 2010-07-23 22:48
浏览 60
已采纳

计算多维数组中的项目总数

How can I count the total items in this array below?

Array
(
    [upload] => Array
        (
            [name] => Array
                (
                    [0] => 1024x768.jpg
                    [1] => 1280x800.jpg
                    [2] => 1280x1024.jpg
                    [3] => 1440x900.jpg
                )

            [type] => Array
                (
                    [0] => image/jpeg
                    [1] => image/jpeg
                    [2] => image/jpeg
                    [3] => image/jpeg
                )

            [tmp_name] => Array
                (
                    [0] => C:\wamp\tmp\php34FE.tmp
                    [1] => C:\wamp\tmp\php353D.tmp
                    [2] => C:\wamp\tmp\php356D.tmp
                    [3] => C:\wamp\tmp\php35AC.tmp
                )

            [error] => Array
                (
                    [0] => 0
                    [1] => 0
                    [2] => 0
                    [3] => 0
                )

            [size] => Array
                (
                    [0] => 469159
                    [1] => 602230
                    [2] => 739779
                    [3] => 707039
                )

        )

)

this is my method, but I think it's stupid! any better ways/ methods to count the total items inside the array?

<pre>
<?php if ($_FILES) {print_r($_FILES);}?>
</pre>

<?php 
echo count($_FILES['upload']['name']);

if(empty($_FILES['upload']['name'][0]))
{
    echo '0 file has been uploaded.';
}
?>

many thanks, Lau

  • 写回答

2条回答 默认 最新

  • duanla4959 2010-07-23 22:59
    关注

    Your approach is certainly not stupid. If you want to count the number of uploads that occurred without error, you could foreach through $_FILES['upload']['error'] to ensure they're all 0.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 哪个tomcat中startup一直一闪而过 找不出问题
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳