0

I am trying to access a multi-dimensional array using PHP. I can access the first level using -

$response['id']

but having trouble with how the second level is defined so I can do -

$response['first level']['second level']

Here is my json response -

Array
(
    [id] => 7181676
    [api_request_id] => 20984853
    [user] => 8305
    [vin] => JTDKN3DU7D1643423
    [make] => Toyota
    [model_name] => Prius
    [model_year] => 2013
    [last_updated] => 2019-02-22T01:08:15.628318Z
    [recall_count] => 1
    [status] => ok
    [recalls] => Array
        (
            [0] => Array
                (
                    [recall_id] => 15753
                    [recall_last_updated] => 2019-02-22T00:33:07.663232Z
                    [recall_age] => 0
                    [nhtsa_id] => 18V684000
                    [oem_id] => J0V
                    [name] => HybridSystem
                    [description] => CollisionRisk
                    [campaign_type] => nhtsa
                    [is_remedy_available] => 1
                    [are_parts_available] => 1
                    [risk_type] => collision
                    [risk_rank] => 5
                    [profit_rank] => 3
                    [overall_rank] => 5
                    [labor_difficulty] => 3
                    [government_id] => 18V684000
                    [is_reviewed] => 1
                    [child] => Array
                        (
                        )
                )
        )
)

How would I get lets say -

$response['profit_rank']
Nick
  • 138,499
  • 22
  • 57
  • 95
Ryan D
  • 741
  • 1
  • 11
  • 29
  • `echo $response['recalls'][0]['profit_rank'];` – Nick Feb 22 '19 at 01:48
  • Possible duplicate of [How do I extract data from JSON with PHP?](https://stackoverflow.com/questions/29308898/how-do-i-extract-data-from-json-with-php) – Nick Feb 22 '19 at 01:49
  • Thank you, I tried using this and it returns blank. – Ryan D Feb 22 '19 at 01:51
  • 1
    It works for me https://3v4l.org/ZKFRO – Nick Feb 22 '19 at 01:52
  • Yes very strange, I will look deeper and see why its not working for me.. – Ryan D Feb 22 '19 at 01:54
  • Ok im a dummy, I switched the VIN to a vehicle without a recall so the data wasnt there.. Works great thank you! Add it as an answer and Ill accept it.. Cheers Mate! – Ryan D Feb 22 '19 at 02:04
  • There's no point adding an answer, it won't really help anyone else. I would just delete the question, or agree with the duplicate flag – Nick Feb 22 '19 at 02:05

0 Answers0