如何在此数组中访问此值?

时间:2018-02-10 01:52:03

标签: php arrays

我做了json_decode,当我var_dump结果变量时,我得到了以下内容。

我粗略地提取了我想要提取的值,但我根本无法弄清楚关联数组的级别来获取该值。

非常感谢任何帮助。

array(2) {
    ["data"]=> array(16) {
        ["expiration_schedule"]=> array(0) { }
        ["last_name"]=> string(11) "johnsonwill"
        ["loyalty_tier_name"]=> string(6) "Silver"
        ["uid"]=> string(20) "**kylesmp1f@yahoo.com**"
        ["dob"]=> string(10) "10/22/1981"
        ["referrer_email"]=> string(0) ""
        ["loyalty_tier_id"]=> string(10) "zrl_silver"
        ["first_name"]=> string(4) "Kyle"
        ["loyalty_enroll_time"]=> string(10) "02/06/2018"
        ["available_points"]=> int(50)
        ["referral_code"]=> string(8) "FJWKAWFHWA"
        ["redeemed_points"]=> int(0)
        ["awarded_points"]=> int(50)
        ["has_opted_out"]=> bool(false)
        ["user_email"]=> string(20) "kylesmp1f@yahoo.com"
        ["pending_points"]=> int(0) 
    }
    ["success"]=> bool(true) 
}

1 个答案:

答案 0 :(得分:1)

你拥有的是一个多维数组。如果您的数组名称是$ test [],则可以通过以下方式访问该值:

echo $test["data"]["uid"];

请参阅此处的完整实施:

$data = array(
    "expiration_schedule" => array(),
    "last_name" => "johnsonwill",
    "loyalty_tier_name" => "Silver",
    "uid" => "kylesmp1f@yahoo.com",
    "dob" => "10/22/1981" ,
    "referrer_email" => "",
    "loyalty_tier_id" => "zrl_silver",
    "first_name" => "Kyle" ,
    "loyalty_enroll_time" => "02/06/2018" ,
    "available_points" => 50,
    "referral_code" => "FJWKAWFHWA" ,
    "redeemed_points" => 0,
    "awarded_points" => 50,
    "has_opted_out" => false,
    "user_email" => "kylesmp1f@yahoo.com" ,
    "pending_points" => 0
);
$success = true;

$test = array("data" => $data, "success" => $success);

echo $test["data"]["uid"];