简体   繁体   English

从PHP数组响应中获取某些值

[英]Fetch Certain Values from a PHP Array Response

I am trying to extract ["details"] from an Array so that it shows 我试图从数组中提取["details"] ,以便显示

Array Value 1=address
Array Value 2=no_match
Array Value 3=address_risk
Array Value 4=low

I tried the following but it doesnt return any value 我尝试了以下操作,但未返回任何值

foreach ($person as $key => $val) {
    print "$key = $val\n";
}

So i should be able to query the Array value if address="no_match" Print "no match" 因此, if address="no_match" Print "no match"我应该能够查询Array值 在此处输入图片说明

Array Value $person 数组值$ person

object(TestScore\Person)#1 (2) {
  ["_values":protected]=>
  array(25) {
    ["id"]=>
    string(24) "57100c7832366100030011e0"
    ["object"]=>
    string(6) "person"
    ["created_at"]=>
    int(1460669560)
    ["updated_at"]=>
    int(1460669560)
    ["status"]=>
    string(5) "valid"
    ["livemode"]=>
    bool(false)
    ["phone_number"]=>
    NULL
    ["ip_address"]=>
    NULL
    ["birth_day"]=>
    int(1)
    ["birth_month"]=>
    int(1)
    ["birth_year"]=>
    int(1990)
    ["name_first"]=>
    string(4) "Jane"
    ["name_middle"]=>
    NULL
    ["name_last"]=>
    string(3) "Doe"
    ["address_street1"]=>
    string(17) "123 Something Ave"
    ["address_street2"]=>
    NULL
    ["address_city"]=>
    string(12) "Newton Falls"
    ["address_subdivision"]=>
    string(2) "OH"
    ["address_postal_code"]=>
    string(5) "44444"
    ["address_country_code"]=>
    string(2) "US"
    ["document_type"]=>
    string(3) "ssn"
    ["document_value"]=>
    string(4) "0000"
    ["note"]=>
    NULL
    ["details"]=>
    object(stdClass)#3 (6) {
      ["address"]=>
      string(8) "no_match"
      ["address_risk"]=>
      string(3) "low"
      ["identification"]=>
      string(8) "no_match"
      ["date_of_birth"]=>
      string(9) "not_found"
      ["ofac"]=>
      string(8) "no_match"
      ["pep"]=>
      string(8) "no_match"
    }
    ["question_sets"]=>
    object(TestScore\QuestionSet)#4 (3) {
      ["_existing":"TestScore\QuestionSet":private]=>
      array(0) {
      }
      ["_values":protected]=>
      array(1) {
        ["id"]=>
        string(24) "57100c7832366100030011e0"
      }
      ["_unsavedValues":protected]=>
      NULL
    }
  }
  ["_unsavedValues":protected]=>
  array(0) {
  }
}
NULL

This: 这个:

foreach ($person as $key => $val) {
    print "$key = $val\n";
}

Should be: 应该:

foreach ($person["details"] as $key => $val) {
    print "$key = $val\n";
}

Reason: 原因:
To pull an array from an array that is nested you need zoom in similar to a file system, where the difference is [first_array][second_array]... 要从嵌套的数组中提取数组,您需要放大类似于文件系统,其中的区别是[first_array] [second_array] ...

The problem is that the _values property is protected and is not visible when iterating from outside the class. 问题是_values属性受到保护,并且从类外部进行迭代时不可见。 For an explanation of a couple ways to access the protected property anyway see this question: 有关无论如何访问受保护属性的几种方式的说明,请参见以下问题:

How to get protected property of object in PHP 如何在PHP中获取对象的受保护属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM