2016-04-14 97 views
0

我試圖從陣列中提取["details"]使其顯示從PHP陣列響應獲取某些值

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

我嘗試以下,但它不返回任何值

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

所以我應該能夠查詢陣列值if address="no_match" Print "no match" enter image description here

數組值$人

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 
+0

的可能的複製[如何獲得PHP對象的保護屬性(http://stackoverflow.com/questions/ 20334355 /如何獲取保護屬性的對象在php) – Daedalus

回答

1

此:

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

應該是:

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

原因:
要從嵌套的數組中拉出數組,需要放大與文件系統類似的差異[first_array] [second_array] ...

+0

謝謝,這有助於 – user580950

+0

花了我一陣子算出陣列也。 –