首页 > 解决方案 > 数组无法获取变量 PHP

问题描述

这可能很简单,但由于某种原因,我无法让我的代码回显变量。抱歉,我是 php 新手。

$file ="https://creator.zoho.com/api/json/los/view/All_Borrowers? 
authtoken=xxx&raw=true";
$bors = file_get_contents($file);
$array = json_decode($bors);
$vars = get_object_vars($array);

退货

 Array
(
[Borrowers] => Array
    (
        [0] => stdClass Object
            (
                [Full_Name] => Steve Smith
                [Email] => fsgfsz@gmail.com
                [Address] => Granby Ct., Aurora, CO, 80012
                [Position] => Borrower
                [ID] => 1159827000004784102
                [Mobile] => +13035550050
                [Application] => Application 1 - 1159827000004784096
            )

        [1] => stdClass Object
            (
                [Full_Name] => Stacy H Sanchez
                [Email] => dfd@gmail.com
                [Address] => Granby, 80012
                [Position] => Co-Borrower
                [ID] => 1159827000004784108
                [Mobile] => +13035550957
                [Application] => Application 1 - 1159827000004784096
            )

    )

)

我在用着:

   echo $vars["Borrowers"][0]["Full_Name"]; 

但它抛出一个错误。不知道我哪里出错了。

标签: phparraysjson

解决方案


Full_name 是对象属性,而不是数组索引

echo $vars["Borrowers"][0]->Full_Name; 

推荐阅读