0

Im trying to access the different results in the following response but can't seem to get it to work:

{
  "id": "REGNOHERE",
  "registration": "REGNOHERE",
  "vehicle": {
    "dvla": {
      "make": "AUDI",
      "model": "A4 SE TDI 6SP",
      "regDate": "2008-09-29",
      "v5cDate": "2011-10-27",
      "vin": "WAUZZZ8K99A099266",
      "colour": "BLUE",
      "source": "UK",
      "exported": "1",
      "exportedDate": "2015-12-09",
      "imported": null,
      "importedNi": null,
      "importedDate": null,
      "body": "4 DOOR SALOON",
      "bodyClass": "CAR",
      "seatingCapacity": 5,
      "wheelplan": "2 AXLE RIGID BODY",
      "co2": 139,
      "cc": 1968,
      "engineNumber": "CAG 120938",
      "engineCode": "2.0 TDI E4",
      "fuel": "HEAVY OIL",
      "maxPower": 105,
      "maxTechMass": 2010
    }

i used the following to decode the response, and tried to acces the data within it

$data = json_decode($response, TRUE);
$carmake['vehicle']['dvla']['make'];

am i missing something??

1
  • 3
    Shouldn't it be $data not $carmake? I'm assuming that the missing 2 } is unintentional paste error. Commented Sep 9, 2016 at 10:40

1 Answer 1

1

$carmake doesn't exist. Your array created from json_decode is $data. To assign $carmake, you can go about it this way:

$carmake = $data['vehicle']['dvla']['make'];
echo $carmake;
// output..
// AUDI
Sign up to request clarification or add additional context in comments.

1 Comment

brilliant thanks! i knew i'd missed something simple!

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.