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 7-1 jmu-java-m02-使用二维数组存储多元线性方程组
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题