簡體   English   中英

Laravel Foreach具有多維數組

[英]Laravel Foreach with a multidimensional array

我正在使用Laravel,我想知道如何將該數組放入foreach中? 閱讀

stdClass Object ( [data] => Array ( [0] => stdClass Object ( [id] => 0001 [type] => Item [attributes] => stdClass Object ( [product_name] => ST Slotted Sport Brake Rotors [part_number] => st126.39027SL [mfr_part_number] => 126.39027SL [part_description] => StopTech Power Slot 00-04 Volvo S40/V40 Front Left Slotted Rotor [category] => Brakes, Rotors & Pads [subcategory] => Brake Rotors - Slotted [dimensions] => Array ( [0] => stdClass Object ( [box_number] => 1 [length] => 15 [width] => 15 [height] => 4 [weight] => 12 ) ) [brand_id] => 56 [brand] => Stoptech [price_group_id] => 129 [price_group] => Stoptech [active] => 1 [regular_stock] => [dropship_controller_id] => 19 [air_freight_prohibited] => [not_carb_approved] => [prop_65] => Unknown [warehouse_availability] => Array ( [0] => stdClass Object ( [location_id] => 01 [can_place_order] => 1 ) [1] => stdClass Object ( [location_id] => 02 [can_place_order] => 1 ) [2] => stdClass Object ( [location_id] => 59 [can_place_order] => 1 ) ) [thumbnail] => https://d5otzd52uv6zz.cloudfront.net/fa33cfb5-0c91-47de-9a49-67f4175a5bff-100.jpg [barcode] => 805890204282 ) ) [1] => stdClass Object ( [id] => 078595 [type] => Item [attributes] => stdClass Object ( [product_name] => RAD Clutch Fork Stop [part_number] => rad20-0262 [mfr_part_number] => 20-0262 [part_description] => Radium Engineering Mitsubishi Evo 8-10 Clutch Fork Stop [category] => Drivetrain [subcategory] => Clutch Uncategorized [dimensions] => Array ( [0] => stdClass Object ( [box_number] => 1 [length] => 4.75 [width] => 4.5 [height] => 4.5 [weight] => 0.5 ) ) [brand_id] => 148 [brand] => Radium Engineering [price_group_id] => 406 [price_group] => Radium Engineering [active] => 1 [regular_stock] => 1 [dropship_controller_id] => 81 [air_freight_prohibited] => [not_carb_approved] => [prop_65] => Unknown [warehouse_availability] => Array ( [0] => stdClass Object ( [location_id] => 01 [can_place_order] => 1 ) [1] => stdClass Object ( [location_id] => 02 [can_place_order] => 1 ) [2] => stdClass Object ( [location_id] => 59 [can_place_order] => 1 ) ) [thumbnail] => https://d32vzsop7y1h3k.cloudfront.net/adb8244ed2d562e078c5ce2928750f2a.JPG ) ) [2] => stdClass Object ( [id] => 095906 [type] => Item [attributes] => stdClass Object ( [product_name] => MLR Trans Rebuild Kits [part_number] => mlr88075K [mfr_part_number] => 88075K [part_description] => McLeod Performance Transmission Rebuild Kit w/ Kolene Steels 4L80E 1997-2011 - Stage 1 [category] => Drivetrain [subcategory] => Transmission Rebuild Kits [dimensions] => Array ( [0] => stdClass Object ( [box_number] => 1 [length] => 24 [width] => 16 [height] => 5.25 [weight] => 14.75 ) ) [brand_id] => 169 [brand] => McLeod Racing [price_group_id] => 456 [price_group] => McLeod Racing [active] => 1 [regular_stock] => [dropship_controller_id] => 116 [air_freight_prohibited] => [not_carb_approved] => [prop_65] => Unknown [warehouse_availability] => Array ( [0] => stdClass Object ( [location_id] => 01 [can_place_order] => 1 ) [1] => stdClass Object ( [location_id] => 02 [can_place_order] => 1 ) [2] => stdClass Object ( [location_id] => 59 [can_place_order] => 1 ) ) ) ) [3] => stdClass Object ( [id] => 1 [type] => Item [attributes] => stdClass Object ( [product_name] => TXS Boost Controllers [part_number] => txs-BC-HPBC [mfr_part_number] => txs-BC-HPBC [part_description] => Turbo XS High Performance Boost Controller [category] => Forced Induction [subcategory] => Boost Controllers [dimensions] => Array ( [0] => stdClass Object ( [box_number] => 1 [length] => 4.75 [width] => 3.25 [height] => 2.25 [weight] => 0.5 ) ) [brand_id] => 63 [brand] => Turbo XS [price_group_id] => 130 [price_group] => Turbo XS [active] => 1 [regular_stock] => 1 [dropship_controller_id] => 0 [air_freight_prohibited] => [not_carb_approved] => [prop_65] => Unknown [warehouse_availability] => Array ( [0] => stdClass Object ( [location_id] => 01 [can_place_order] => 1 ) [1] => stdClass Object ( [location_id] => 02 [can_place_order] => 1 ) [2] => stdClass Object ( [location_id] => 59 [can_place_order] => 1 ) ) [thumbnail] => https://d5otzd52uv6zz.cloudfront.net/92670bde-a650-4ae6-a53e-0da8b2a26d1c-100.jpg [barcode] => 053176487038 ) )

謝謝!

只需遍歷您的數據

foreach($yourvar->data as $key=> $data){
    echo $data->id; 
}

如果得到了StdClass對象,則意味着您正在通過->遍歷對象,如果您有數組,則可以通過$data['key']打印

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM