douan5151 2014-08-14 18:01
浏览 30
已采纳

访问数组中的对象属性

Using an API from a third party app, I use an API call:

print_r($response->response());

the result:

  (
        [0] => stdClass Object
            (
                [id] => 41
                [id_format] => 2014-{num}
                [id_value] => 530
                [client_id] => 37
                [date_billed] => 2014-08-13 20:12:44
                [date_due] => 2014-08-13 20:12:44
                [date_closed] => 
                [date_autodebit] => 
                [status] => active
                [subtotal] => 15.0000
                [total] => 15.0000
                [paid] => 0.0000
                [previous_due] => 0.0000
                [currency] => USD
                [note_public] => 
                [note_private] => 
                [id_code] => 2014-530
                [delivery_date_sent] => 2014-08-13 20:15:10
                [client_id_code] => 1522
                [client_first_name] => Nate
                [client_last_name] => TestAccount
                [client_company] => 
                [client_address1] => 
                [client_email] => xnumber7seven@gmail.com
                [due] => 15.0000
            )

    )

I am trying to access these elements to no avail. I have tried the following so far:

$test =  $response->response()[0]->id;
$test =  $response->response(0)->id;
$test =  $response->response()->[0]->id;
$test =  $response->response()->[0]id;

I cannot seem to figure out the syntax to set an element to a variable.

Please do not flame, I am trying my best and would appreciate an extra set of eyes to help my stupidity.

  • 写回答

1条回答 默认 最新

  • dongyu3967 2014-08-14 18:03
    关注

    Try,

    $data = $response->response(); 
    echo $data[0]->id;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,
  • ¥15 spaceclaim模型变灰色