【问题标题】:Count items inside an array计算数组中的项目
【发布时间】:2018-05-18 09:29:02
【问题描述】:

所以我有一个充满随机事物的数组(比如说水果)

$fruit = array ("Banana", "Strawberry", "Apple",);

后跟一个

echo implode (glue ' and ', $fruit); 

应该列出数组中出现的每一个水果

现在,我如何计算列表中出现的项目数量?至于我如何让代码显示它是 3 个项目

【问题讨论】:

标签: php arrays echo


【解决方案1】:

可以使用php的count()方法。

Reference

为了显示金额,您可以这样使用:

echo "Amount: " . count($fruit);

【讨论】:

    【解决方案2】:

    您可以使用 Count()。

    $fruit = array ("Banana", "Strawberry", "Apple",);
    
    echo implode(' and ', $fruit) . " is " . count($fruit) . " fruits";
    // Banana and Strawberry and Apple is 3 fruits
    

    https://3v4l.org/19LqD

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-18
      • 2011-07-08
      • 1970-01-01
      • 1970-01-01
      • 2017-11-19
      • 1970-01-01
      相关资源
      最近更新 更多