dsbtwy1329 2012-09-20 03:00
浏览 76
已采纳

计算数组中非空项的数量? [重复]

Possible Duplicate:
how to count non-empty entries in php array?

I want to count the number of keys in an array that aren't empty/null.

EG:
array(1>'asdf',2>'fdas',3>'');

count($array) would return 3, I want a function that returns 2 as 3 is empty

Are there any php built in functions to do this? How can it be done?

  • 写回答

1条回答 默认 最新

  • dousonghs58612 2012-09-20 03:03
    关注

    Use:

    count(array_filter($array));
    

    array array_filter ( array $input [, callable $callback = "" ] )

    If no callback is supplied, all entries of input equal to FALSE (see converting to boolean) will be removed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动