1

I want to return for each vehicule of the API the brand name and the model name

i'm actualy using this loop:

$vehiculecount=count($data);
for($x = 0; $x < $vehiculecount; $x++) {
    echo $data[$x];
    echo $data[brand][name];
    echo "<br>";
}

That actualy return me only :

Array
Array
Array
Array
Array
Array


 ...

This is what i'm getting in PHP with curl to an API :

{
totalResult: "150",
nbPageList: 2,
createdAt: "2018-05-28T09:23:05+0200",
updatedAt: "2018-05-28T10:55:14+0200",
reference: "5nqts",
reportNumber: 5,
country: "FR",
state: "vehicle.state.parc",
brand: {
reference: "56f50a85cb0f8",
name: "CITROEN"
},
model: {
reference: "57f4d339e38e3",
name: "C3 AIRDREAM BUSINESS"
},

I want to get only 'brand''name' for each vehicle for exemple. Thx a lot for your help !

2
  • use var_dump() instead of echo(), until you figure out what your data is Commented May 28, 2018 at 15:17
  • 1
    Yes i do it, thx ! Commented May 28, 2018 at 15:28

1 Answer 1

3

First, you should dump, as debugging purpose, the $data object in your loop. Then, you should see that inside your loop, to acces to an element by its number, you have to use the indexed access like this :

echo $data[$x][brand][name];

Also, to access the brand and name index, you have to use string-key index like this : $data[$x]['brand']['name']

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

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.