douping3860 2013-05-21 12:57
浏览 20

非法字符串偏移,如何使用此数据[关闭]

I've got an array returned from an API call like below. When I try to access the data using its key, I get an illegal string offset. I believe it's caused by the fact that the key names don't have ' around them, but I can't do any thing about that as the data is coming from an external source.

Any idea why this is happening or what I can do about it ?

 [data] => Array
        (
            [latest] => Array
                (
                    [value] => 123.59000
                    [value_int] => 12359000
                    [display] => $123.59000
                    [display_short] => $123.59
                    [currency] => USD
                )

im trying to access the data like this

     echo $element['value'];
  • 写回答

1条回答 默认 最新

  • dongyan3018 2013-05-21 12:59
    关注

    If you are looping your $array, you already have value in $element variable.

    You can expand also array`s keys with:

    foreach ($array as $key => $value) {
         echo $key . ' = ' . $value;
    }
    

    If you want to access value with key, just use without looping:

    echo $array['value'];
    

    According to your edit - if you have large array assigned to the $array variable, loop array value assigned to data key with:

    foreach ( $array['data'] as $element ) {
        echo $element['value'];
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据