newlearner newlearner - 6 months ago 19
SQL Question

having difficulty to get style id from edmunds api

Array ( [make] => Array ( [id] => 200000201 [name] => Nissan [niceName] => nissan ) [model] => Array ( [id] => Nissan_Pathfinder [name] => Pathfinder [niceName] => pathfinder ) [engine] => Array ( [equipmentType] => ENGINE [availability] => USED [cylinder] => 6 [size] => 3.5 [configuration] => V [fuelType] => regular unleaded [horsepower] => 260 [type] => gas [code] => VQ35DE [rpm] => Array ( [horsepower] => 6400 [torque] => 4400 ) [valve] => Array ( [gear] => double overhead camshaft ) ) [transmission] => Array ( [id] => 200405221 [name] => continuously variableA [equipmentType] => TRANSMISSION [availability] => STANDARD [automaticType] => Continuously variable [transmissionType] => AUTOMATIC [numberOfSpeeds] => continuously variable ) [drivenWheels] => front wheel drive [numOfDoors] => 4 [options] => Array ( ) [colors] => Array ( [0] => Array ( [category] => Interior [options] => Array ( [0] => Array ( [id] => 200439557 [name] => Almond Leather [equipmentType] => COLOR [availability] => USED ) ) ) [1] => Array ( [category] => Exterior [options] => Array ( [0] => Array ( [id] => 200439553 [name] => Cayenne Red Metallic [equipmentType] => COLOR [availability] => USED ) ) ) ) [manufacturerCode] => 25513 [price] => Array ( [baseMSRP] => 34850 [baseInvoice] => 31770 [deliveryCharges] => 845 [usedTmvRetail] => 22236 [usedPrivateParty] => 20769 [usedTradeIn] => 19116 [estimateTmv] => ) [categories] => Array ( [market] => Crossover [EPAClass] => Sport Utility Vehicles [vehicleSize] => Large [crossover] => Car [primaryBodyType] => SUV [vehicleStyle] => 4dr SUV [vehicleType] => SUV ) [vin] => 5N1AR2MNXDC676161 [squishVin] => 5N1AR2MNDC [years] => Array ( [0] => Array ( [id] => 100539157 [year] => 2013 [styles] => Array ( [0] => Array ( [id] => 200439517 [name] => SL 4dr SUV (3.5L 6cyl CVT) [submodel] => Array ( [body] => SUV [modelName] => Pathfinder SUV [niceName] => suv ) [trim] => SL ) ) ) ) [matchingType] => SQUISHVIN [MPG] => Array ( [highway] => 26 [city] => 20 ) ) NissanPathfinder2013


from this array I get
make
,
model
, and
year
like this:

$ed_json=file_get_contents($ed_url);
$ed_array= json_decode($ed_json, true);
print_r($ed_array);
$make=$ed_array['make']['name'];
$model=$ed_array['model']['name'];
$year=$ed_array['years']['0']['year'];


echo $make;
echo $model;
echo $year;


now I am doing the same thing to get style id but I cannot get it.
this is the code for style id:

$id=$ed_array['styles']['0']['id'];
echo $id;

Answer

Array for years :

[years] => Array (
    [0] => Array (
        [id] => 100539157
        [year] => 2013
        [styles] => Array (
            [0] => Array (
                [id] => 200439517
                [name] => SL 4dr SUV (3.5L 6cyl CVT)
                [submodel] => Array (
                    [body] => SUV
                    [modelName] => Pathfinder SUV
                    [niceName] => suv
                )
                [trim] => SL
            )
        )
    )
)

As you can see [styles][0][id] is in [years][0]. So, to get style id you can do :

$style = $ed_array['years'][0]['styles'][0]['id'];
Comments