dongshi6844 2018-10-15 11:22
浏览 319
已采纳

b / w可数和不可数对象有什么区别

I am trying out to find difference b/w a countable and a non countable object

First I found out the Type of object

echo gettype($data["current_fiat_currency"]);

Which is a Object

But when i had checked that it is a countable object or not

var_dump($data["current_fiat_currency"] instanceof Countable );

then it returns

 False

Below is the object content

var_dump($data["current_fiat_currency"]);

object(stdClass)[2010]
  public 'id' => string '1399' (length=4)
  public 'currency_name' => string 'US Dollar' (length=9)
  public 'currency_slug' => string '' (length=0)
  public 'currency_code' => string 'USD' (length=3)
  public 'currency_logo' => string '0' (length=1)
  public 'currency_type' => string '3' (length=1)
  public 'logo' => string '.png' (length=4)
  public 'exe' => string '0' (length=1)
  public 'logo_exe' => string '1' (length=1)
  public 'symbol_native' => string '$' (length=1)
  public 'symbol' => string '$' (length=1)
  public 'name_plural' => string 'US dollars' (length=10)
  public 'market_cap' => string '0' (length=1)
  public 'circulating_supply' => string '0' (length=1)
  public 'max_supply' => string '0' (length=1)
  public 'total_supply' => string '0' (length=1)
  public 'cryptoid_info_exe' => string '0' (length=1)
  public 'show_on_website' => string '1' (length=1)
  public 'default_selected' => string '1' (length=1)
  public 'exchange_rate' => string '1' (length=1)
  public 'currencies_stats_exe' => string '0' (length=1)
  public 'currencies_stats_last_updated' => null
  public 'mineable_or_not' => string '0' (length=1)
  public 'show_on_top_bar' => string '0' (length=1)
  public 'added_date' => string '2018-01-11 05:21:37' (length=19)
  public 'graph_size_chart_status' => string '0' (length=1)
  public 'twitter' => null
  public 'reddit' => null
  public 'status' => string '1' (length=1)
  public 'for_pair_status' => string '0' (length=1)

So how i can convert a existing object to countable if it is not countable according to Php 7.2 because my codes working fine with Php 7.0.

  • 写回答

3条回答 默认 最新

  • douhuan3420 2018-10-15 11:55
    关注

    A hack may be

    echo count((array) $data["current_fiat_currency"]);
    

    It's just a patching solution and I think it'll work in just some cases and you should not rely on it.

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

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境