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条)

报告相同问题?

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?