I am trying to form variables out of an output received from a web service. The web service provides detailed information regarding a vehicle after entering the vehicle's VIN into the system. Below is a portion of the output one receives after entering a VIN.
object(stdClass)#2 (14) {
["responseStatus"]=>
object(stdClass)#3 (2) {
["responseCode"]=>
string(10) "Successful"
["description"]=>
string(10) "Successful"
}
["vinDescription"]=>
object(stdClass)#4 (11) {
["WorldManufacturerIdentifier"]=>
string(17) "Germany Audi Nsu "
}
["vin"]=>
string(17) "WAUUL78E38A092113"
["modelYear"]=>
int(2008)
["division"]=>
string(4) "Audi"
["modelName"]=>
string(2) "S4"
["styleName"]=>
string(13) "5dr Avant Wgn"
["bodyType"]=>
string(11) "Wagon 4 Dr."
["drivingWheels"]=>
string(3) "AWD"
["builddata"]=>
string(2) "no"
}
["style"]=>
array(2) {
[0]=>
object(stdClass)#26 (17) {
["division"]=>
object(stdClass)#27 (2) {
["_"]=>
string(4) "Audi"
["id"]=>
int(4)
}
["subdivision"]=>
object(stdClass)#28 (2) {
["_"]=>
string(4) "Audi"
["id"]=>
int(5020)
}
["model"]=>
object(stdClass)#29 (2) {
["_"]=>
string(2) "S4"
["id"]=>
int(17308)
}
["basePrice"]=>
object(stdClass)#30 (4) {
["unknown"]=>
bool(false)
["invoice"]=>
float(46137)
["msrp"]=>
float(49610)
["destination"]=>
float(775)
}
["bodyType"]=>
object(stdClass)#31 (3) {
["_"]=>
string(13) "Station Wagon"
["id"]=>
int(7)
["primary"]=>
bool(true)
}
["marketClass"]=>
object(stdClass)#32 (2) {
["_"]=>
string(11) "Small Wagon"
["id"]=>
int(53)
}
["acode"]=>
object(stdClass)#33 (1) {
["_"]=>
string(13) "USB80AUC085A0"
}
["id"]=>
int(292015)
["modelYear"]=>
int(2008)
["name"]=>
string(17) "5dr Avant Wgn Man"
["nameWoTrim"]=>
string(17) "5dr Avant Wgn Man"
["mfrModelCode"]=>
string(6) "8ED549"
["fleetOnly"]=>
bool(false)
["modelFleet"]=>
bool(false)
["passDoors"]=>
int(4)
["altBodyType"]=>
string(13) "Station Wagon"
["drivetrain"]=>
string(15) "All Wheel Drive"
}
So far I have been successful in creating and calling the variables stored as objects.
Here is what I have done so far.
Create the variables based on the output:
$manuf = $result->vinDescription->WorldManufacturerIdentifier;
$vin = $result->vinDescription->vin;
$year = $result->vinDescription->modelYear;
$make = $result->vinDescription->division;
$model = $result->vinDescription->modelName;
$style = $result->vinDescription->styleName;
$body= $result->vinDescription->bodyType;
Print the variables to describe the vehicle:
echo "Manufacturer: ".$manuf;
echo "<br>";
echo "Year: ".$year;
echo "<br>";
echo "Make: ".$make;
echo "<br>";
echo "Model: ".$model;
echo "<br>";
echo "Trim: ".$style;
echo "<br>";
echo "Body style: ".$body;
The output:
Manufacturer: Germany Audi Nsu
Year: 2008
Make: Audi
Model: S4
Trim: 5dr Avant Wgn
Body style: Wagon 4 Dr.
Drive type: Small Wagon
I am having trouble creating and calling certain variables that seem to be nested in arrays. The two variables I am interested in creating are Number of Doors and Drivetrain. They are in the bottom of the original output named passDoors
and drivetrain
.
I have tried to create the variable like this: $drivetype = $result['style']['drivetrain'];
However, I been unsuccessful. Any ideas as to how I can create and call passDoors
and drivetrain
from the original output? Any feedback is appreciated.
Encounter another roadblock. It seems the further I dig into the data the more complex calling data to create new variables. Here is the section I am struggling with:
["technicalSpecification"]=>
array(97) {
[0]=>
object(stdClass)#640 (2) {
["titleId"]=>
int(1)
["value"]=>
array(2) {
[0]=>
object(stdClass)#641 (3) {
["styleId"]=>
array(2) {
[0]=>
int(292015)
[1]=>
int(292016)
}
["value"]=>
string(7) "Audi S4"
["condition"]=>
string(3) "-PT"
}
[1]=>
object(stdClass)#642 (3) {
["styleId"]=>
array(2) {
[0]=>
int(292015)
[1]=>
int(292016)
}
["value"]=>
string(7) "Audi S4"
["condition"]=>
string(0) ""
}
}
}
[1]=>
object(stdClass)#643 (2) {
["titleId"]=>
int(2)
["value"]=>
object(stdClass)#644 (3) {
["styleId"]=>
array(2) {
[0]=>
int(292015)
[1]=>
int(292016)
}
["value"]=>
string(12) "5 Door Wagon"
["condition"]=>
string(0) ""
}
}
[2]=>
object(stdClass)#645 (2) {
["titleId"]=>
int(6)
["value"]=>
object(stdClass)#646 (3) {
["styleId"]=>
array(2) {
[0]=>
int(292015)
[1]=>
int(292016)
}
["value"]=>
string(15) "All-Wheel Drive"
["condition"]=>
string(0) ""
}
}
I am attempting to extract "Audi S4", "5 Door Wagon", and "All-Wheel Drive"
Thanks so much for any input.