因此,我正在使用一個API用於車輛,並且我正在運行到一堵牆中,並希望從中獲得一些有更多經驗的輸入......我將從展示了我從API調用返回的數據的一個示例。用PHP顯示一個API數組的部分
Array
(
[make] => Array
(
[id] => 200003644
[name] => Chrysler
[niceName] => chrysler
)
[model] => Array
(
[id] => Chrysler_200
[name] => 200
[niceName] => 200
)
[engine] => Array
(
[equipmentType] => ENGINE
[availability] => USED
[cylinder] => 6
[size] => 3.6
[configuration] => V
[fuelType] => flex-fuel (unleaded/E85)
[horsepower] => 295
[type] => flex-fuel (FFV)
[code] => ERB
[rpm] => Array
(
[horsepower] => 6350
[torque] => 4250
)
[valve] => Array
(
[gear] => double overhead camshaft
)
)
[transmission] => Array
(
[equipmentType] => TRANSMISSION
[availability] => USED
[transmissionType] => AUTOMATIC
)
[drivenWheels] => front wheel drive
[numOfDoors] => 4
[options] => Array
(
[0] => Array
(
[category] => Safety
[options] => Array
(
[0] => Array
(
[id] => 200741607
[name] => SafetyTec
[description] => Adaptive Cruise Control with Stop & Go; Advanced Brake Assist; Automatic high beam control; Blind Spot and Cross Path Detection; Full Speed Forward Collision Warning Plus; Lane Departure Warning Plus; Parallel and Perpendicular Park Assist with Stop; Rain sensitive windshield wipers
[equipmentType] => OPTION
[availability] => All C/All C Platinum
)
)
)
[1] => Array
(
[category] => Package
[options] => Array
(
[0] => Array
(
[id] => 200741480
[name] => Quick Order Package 26N (Fleet)
[description] => Vehicle with standard equipment
[equipmentType] => OPTION
[availability] => All C
)
[1] => Array
(
[id] => 200741610
[name] => Premium Group
[description] => 115V auxiliary power outlet; Exterior mirrors with memory; Heated 2 tone leather steering wheel; Luxury door trim panel; Premium leather trimmed ventilated front seats with leather seat cushion; Radio/driver seat/Climate control with memory; Real wood/bronze chrome interior accents
[equipmentType] => OPTION
[availability] => All C/All C Platinum
)
[2] => Array
(
[id] => 200741715
[name] => Premium Lighting Group
[description] => HID headlamps with LED daytime running lights; LED fog lamps
[equipmentType] => OPTION
[availability] => All S/All C
)
[3] => Array
(
[id] => 200741805
[name] => Navigation And Sound Group I
[description] => 506 watt amplifier; SiriusXM traffic with 5-year of included service; Travel Link Service with 5-year of included service; 9 amplified speakers with subwoofer; GPS navigation; HD radio; Uconnect 8.4AN AM/FM/SiriusXM/Hard disc drive/Bluetooth/Navigation
[equipmentType] => OPTION
[availability] => All C
)
)
)
)
所以,如果我有存儲在一個變量這個數據名爲$數據,例如,我可以做這樣的事情,它的工作原理:
foreach ($data['options'] as $options) {
echo $options['category'];
}
,將返回我的「安全」和「包」。
但是,如果我想獲得車輛的品牌和我做這樣的事情:
foreach ($data['make'] as $make) {
echo $make['name'];
}
它只是返回我的價值:從化妝名抄送(大寫C和小寫字母c從make niceName)。它爲什麼這樣做?我究竟做錯了什麼?
謝謝!
: - \你說得對,我想這很難。謝謝! – lpangm03