0

I am trying to extract ["details"] from an Array so that it shows

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" enter image description here

Array Value $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
1

2 Answers 2

1

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]...

Sign up to request clarification or add additional context in comments.

1 Comment

took me a while to figure out arrays also.
0

The problem is that the _values property is protected and is not visible when iterating from outside the class. 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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.