Php 结果仅显示在foreach内部

Php 结果仅显示在foreach内部,php,arrays,foreach,Php,Arrays,Foreach,我试图获取会话数组中产品的数量,但由于某些原因,如果我有下面的代码,它就无法工作 $amount = $array->products['quantity']; 如果数组是一个多维数组,我使用下面的代码来获得压缩 $zip = $array->BT['zip']; 但是如果我使用foreach,我会得到我需要的结果(见下文) 问题是我有一个计算运费的foreach,它需要数量乘以重量,所以我不能使用上面的foreach,因为计算器使用不同的foreach 请参见下面的阵列打印:

我试图获取会话数组中产品的数量,但由于某些原因,如果我有下面的代码,它就无法工作

$amount = $array->products['quantity'];
如果数组是一个多维数组,我使用下面的代码来获得压缩

$zip = $array->BT['zip'];
但是如果我使用foreach,我会得到我需要的结果(见下文)

问题是我有一个计算运费的foreach,它需要数量乘以重量,所以我不能使用上面的foreach,因为计算器使用不同的foreach

请参见下面的阵列打印:

stdClass Object ( [products] => Array ( [1613] => stdClass Object ( [virtuemart_manufacturer_id] => 29 [slug] => samsung-ua60es8000-60-smart-interaction-3d-slim-led-tv [published] => 1 [virtuemart_product_price_id] => 1613 [virtuemart_product_id] => 1613 [virtuemart_shoppergroup_id] => [product_price] => 46999.00000 [override] => [product_override_price] => 0.00000 [product_tax_id] => 0 [product_discount_id] => 0 [product_currency] => 153 [virtuemart_vendor_id] => 1 [product_parent_id] => 0 [product_sku] => LC-S60ES8000 [product_name] => Samsung ua60ES8000 60" Smart Interaction 3D Slim LED TV [product_s_desc] => Samsung ua60ES8000 60" Smart Interaction 3D Slim LED TV with intuitive voice and voice/motion control + built-in camera + face recognition + personal video recorder ready + time shift ready [product_weight] => 5.0000 [product_weight_uom] => KG [product_length] => 0.0000 [product_width] => 0.0000 [product_height] => 0.0000 [product_lwh_uom] => M [product_in_stock] => 0 [product_ordered] => 0 [product_sales] => 0 [product_unit] => S1 [product_packaging] => 0 [min_order_level] => 0 [max_order_level] => 0 [virtuemart_media_id] => Array ( [0] => 4380 ) [image] => VmImage Object ( [media_attributes] => 0 [setRole] => [_foldersToTest:VmMediaHandler:private] => Array ( [0] => C:\wamp\www\Testing\images\stories\virtuemart\product\ [1] => C:\wamp\www\Testing\images\stories\virtuemart\product\resized\ ) [_actions:VmMediaHandler:private] => Array ( ) [_mLocation:VmMediaHandler:private] => Array ( ) [_hidden:VmMediaHandler:private] => Array ( ) [virtuemart_media_id] => 4380 [theme_url] => http://127.0.0.1/testing/components/com_virtuemart/ [virtuemart_vendor_id] => 1 [file_title] => samsung ua60d8000 3d led tv , silver , 60 wide , 1080p full hd.jpg_product [file_description] => [file_meta] => [file_mimetype] => image/jpeg [file_type] => product [file_url] => images/stories/virtuemart/product/samsung ua46es8000 46 smart interaction 3d slim led tv5.jpg [file_url_thumb] => images/stories/virtuemart/product/resized/samsung ua46es8000 46 smart interaction 3d slim led tv5_250x250.jpg [published] => 1 [file_is_downloadable] => 0 [file_is_forSale] => 0 [file_is_product_image] => 0 [shared] => 0 [file_params] => [_translatable] => [_tablePreFix] => [created_on] => 0000-00-00 00:00:00 [created_by] => 0 [modified_on] => 2013-08-20 19:25:37 [modified_by] => 42 [locked_on] => 0000-00-00 00:00:00 [locked_by] => 0 [file_url_folder] => images/stories/virtuemart/product/ [file_path_folder] => images\stories\virtuemart\product\ [file_url_folder_thumb] => images/stories/virtuemart/product/resized/ [file_name] => samsung ua46es8000 46 smart interaction 3d slim led tv5 [file_extension] => jpg [media_role] => file_is_displayable ) [categories] => Array ( [0] => 106 ) [virtuemart_category_id] => 106 [category_name] => LED Tv's [link] => /testing/index.php/shop/spectratec/monitors/led-tv-s/samsung-ua60es8000-60-smart-interaction-3d-slim-led-tv-detail [packaging] => [quantity] => 1 [url] => /testing/index.php/shop/spectratec/monitors/led-tv-s/samsung-ua60es8000-60-smart-interaction-3d-slim-led-tv-detail [customfields] => [cart_item_id] => 1613 ) [3994] => stdClass Object ( [virtuemart_manufacturer_id] => 29 [slug] => samsung-ua65es8000-65-smart-interaction-3d-slim-led-tv [published] => 1 [virtuemart_product_price_id] => 3994 [virtuemart_product_id] => 3994 [virtuemart_shoppergroup_id] => [product_price] => 48999.00000 [override] => [product_override_price] => 0.00000 [product_tax_id] => 0 [product_discount_id] => 0 [product_currency] => 153 [virtuemart_vendor_id] => 1 [product_parent_id] => 0 [product_sku] => LC-S65ES8000 [product_name] => Samsung ua65ES8000 65" Smart Interaction 3D Slim LED TV [product_s_desc] => Samsung ua65ES8000 65" Smart Interaction 3D Slim LED TV with intuitive voice and voice/motion control + built-in camera + face recognition + personal video recorder ready + time shift ready [product_weight] => 5.0000 [product_weight_uom] => KG [product_length] => 0.0000 [product_width] => 0.0000 [product_height] => 0.0000 [product_lwh_uom] => M [product_in_stock] => 0 [product_ordered] => 0 [product_sales] => 0 [product_unit] => S2 [product_packaging] => 0 [min_order_level] => 0 [max_order_level] => 0 [virtuemart_media_id] => Array ( [0] => 4381 ) [image] => VmImage Object ( [media_attributes] => 0 [setRole] => [_foldersToTest:VmMediaHandler:private] => Array ( [0] => C:\wamp\www\Testing\images\stories\virtuemart\product\ [1] => C:\wamp\www\Testing\images\stories\virtuemart\product\resized\ ) [_actions:VmMediaHandler:private] => Array ( ) [_mLocation:VmMediaHandler:private] => Array ( ) [_hidden:VmMediaHandler:private] => Array ( ) [virtuemart_media_id] => 4381 [theme_url] => http://127.0.0.1/testing/components/com_virtuemart/ [virtuemart_vendor_id] => 1 [file_title] => samsung ua46es8000 46 smart interaction 3d slim led tv2.jpg [file_description] => [file_meta] => [file_mimetype] => image/jpeg [file_type] => product [file_url] => images/stories/virtuemart/product/samsung ua46es8000 46 smart interaction 3d slim led tv2.jpg [file_url_thumb] => images/stories/virtuemart/product/resized/samsung ua46es8000 46 smart interaction 3d slim led tv2_250x250.jpg [published] => 1 [file_is_downloadable] => 0 [file_is_forSale] => 0 [file_is_product_image] => 0 [shared] => 0 [file_params] => [_translatable] => [_tablePreFix] => [created_on] => 0000-00-00 00:00:00 [created_by] => 0 [modified_on] => 2013-08-21 21:14:40 [modified_by] => 42 [locked_on] => 0000-00-00 00:00:00 [locked_by] => 0 [file_url_folder] => images/stories/virtuemart/product/ [file_path_folder] => images\stories\virtuemart\product\ [file_url_folder_thumb] => images/stories/virtuemart/product/resized/ [file_name] => samsung ua46es8000 46 smart interaction 3d slim led tv2 [file_extension] => jpg [media_role] => file_is_displayable ) [categories] => Array ( [0] => 106 ) [virtuemart_category_id] => 106 [category_name] => LED Tv's [link] => /testing/index.php/shop/spectratec/monitors/led-tv-s/samsung-ua65es8000-65-smart-interaction-3d-slim-led-tv-detail [packaging] => [quantity] => 1 [url] => /testing/index.php/shop/spectratec/monitors/led-tv-s/samsung-ua65es8000-65-smart-interaction-3d-slim-led-tv-detail [customfields] => [cart_item_id] => 3994 ) [4784] => stdClass Object ( [virtuemart_manufacturer_id] => 29 [slug] => samsung-75-smart-interaction-3d-slim-led-tv [published] => 1 [virtuemart_product_price_id] => 4784 [virtuemart_product_id] => 4784 [virtuemart_shoppergroup_id] => [product_price] => 79999.00000 [override] => [product_override_price] => 0.00000 [product_tax_id] => 0 [product_discount_id] => 0 [product_currency] => 153 [virtuemart_vendor_id] => 1 [product_parent_id] => 0 [product_sku] => LC-S75ES9000 [product_name] => Samsung 75" Smart Interaction 3D Slim LED TV [product_s_desc] => Samsung ua75ES9000 75" Smart Interaction 3D Slim LED TV ,36.2mm ultra slim design with 5mm slim bezel ,clear motion plus 900hz ,1920x1080 Full HD3x HDMi+ component+ RCA+3x usb+optical digial audio+RF-in for atellite [product_weight] => 4.0000 [product_weight_uom] => KG [product_length] => 30.0000 [product_width] => 20.0000 [product_height] => 40.0000 [product_lwh_uom] => CM [product_in_stock] => 0 [product_ordered] => 0 [product_sales] => 0 [product_unit] => S1 [product_packaging] => 0 [min_order_level] => 0 [max_order_level] => 0 [virtuemart_media_id] => Array ( [0] => 5556 ) [image] => VmImage Object ( [media_attributes] => 0 [setRole] => [_foldersToTest:VmMediaHandler:private] => Array ( [0] => C:\wamp\www\Testing\images\stories\virtuemart\product\ [1] => C:\wamp\www\Testing\images\stories\virtuemart\product\resized\ ) [_actions:VmMediaHandler:private] => Array ( ) [_mLocation:VmMediaHandler:private] => Array ( ) [_hidden:VmMediaHandler:private] => Array ( ) [virtuemart_media_id] => 5556 [theme_url] => http://127.0.0.1/testing/components/com_virtuemart/ [virtuemart_vendor_id] => 1 [file_title] => samsung 75 smart interaction 3d slim led tv.jpg [file_description] => [file_meta] => [file_mimetype] => image/jpeg [file_type] => product [file_url] => images/stories/virtuemart/product/samsung 75 smart interaction 3d slim led tv.jpg [file_url_thumb] => images/stories/virtuemart/product/resized/samsung 75 smart interaction 3d slim led tv_250x250.jpg [published] => 1 [file_is_downloadable] => 0 [file_is_forSale] => 0 [file_is_product_image] => 0 [shared] => 0 [file_params] => [_translatable] => [_tablePreFix] => [created_on] => 0000-00-00 00:00:00 [created_by] => 0 [modified_on] => 2013-08-20 19:24:31 [modified_by] => 42 [locked_on] => 0000-00-00 00:00:00 [locked_by] => 0 [file_url_folder] => images/stories/virtuemart/product/ [file_path_folder] => images\stories\virtuemart\product\ [file_url_folder_thumb] => images/stories/virtuemart/product/resized/ [file_name] => samsung 75 smart interaction 3d slim led tv [file_extension] => jpg [media_role] => file_is_displayable ) [categories] => Array ( [0] => 106 [1] => 118 ) [virtuemart_category_id] => 106 [category_name] => LED Tv's [link] => /testing/index.php/shop/spectratec/monitors/led-tv-s/samsung-75-smart-interaction-3d-slim-led-tv-detail [packaging] => [quantity] => 1 [url] => /testing/index.php/shop/spectratec/monitors/led-tv-s/samsung-75-smart-interaction-3d-slim-led-tv-detail [customfields] => [cart_item_id] => 4784 ) ) [vendorId] => 1 [lastVisitedCategoryId] => 0 [virtuemart_shipmentmethod_id] => 0 [virtuemart_paymentmethod_id] => 1 [automaticSelectedShipment] => [automaticSelectedPayment] => 1 [BT] => Array ( [email] => john123@email.com [title] => Mr [first_name] => john [last_name] => smith [address_1] => 1 smith str [address_2] => long hill cape town [zip] => 8000 [city] => cape town [virtuemart_country_id] => 193 [virtuemart_state_id] => 578 [phone_1] => 000-000-000 ) [ST] => 0 [tosAccepted] => 1 [customer_comment] => [couponCode] => [cartData] => Array ( [duty] => 1 [payment] => 0 [paymentName] => EFT & other transactions directly to our bank [DBTaxRulesBill] => Array ( ) [shipmentName] => shipping cost will be given in quote [taxRulesBill] => Array ( ) [DATaxRulesBill] => Array ( ) ) [lists] => Array ( [shipTo] =>   - Default (Same as Billing)
[billTo] => 39 ) [pricesUnformatted] => Array ( [basePrice] => 210668.409 [basePriceWithTax] => 0 [discountedPriceWithoutTax] => 0 [salesPrice] => 210668.409 [taxAmount] => 0 [salesPriceWithDiscount] => 0 [discountAmount] => 0 [priceWithoutTax] => 210668.409 [subTotalProducts] => 0 [9Diff] => 3999.95 [11Diff] => 11759.853 [1613] => Array ( [costPrice] => 46999.00000 [basePrice] => 56257.803 [basePriceVariant] => 56257.803 [basePriceWithTax] => 0 [discountedPriceWithoutTax] => 0 [priceBeforeTax] => 56257.803 [salesPrice] => 56257.803 [taxAmount] => 0 [salesPriceWithDiscount] => 0 [salesPriceTemp] => 56257.803 [discountAmount] => 0 [priceWithoutTax] => 56257.803 [variantModification] => 0 [DBTax] => Array ( ) [Tax] => Array ( ) [VatTax] => Array ( ) [DATax] => Array ( ) [subtotal] => 56257.803 [subtotal_tax_amount] => 0 [subtotal_discount] => 0 [subtotal_with_tax] => 56257.803 ) [3994] => Array ( [costPrice] => 48999.00000 [basePrice] => 58651.803 [basePriceVariant] => 58651.803 [basePriceWithTax] => 0 [discountedPriceWithoutTax] => 0 [priceBeforeTax] => 58651.803 [salesPrice] => 58651.803 [taxAmount] => 0 [salesPriceWithDiscount] => 0 [salesPriceTemp] => 58651.803 [discountAmount] => 0 [priceWithoutTax] => 58651.803 [variantModification] => 0 [DBTax] => Array ( ) [Tax] => Array ( ) [VatTax] => Array ( ) [DATax] => Array ( ) [subtotal] => 58651.803 [subtotal_tax_amount] => 0 [subtotal_discount] => 0 [subtotal_with_tax] => 58651.803 ) [4784] => Array ( [costPrice] => 79999.00000 [basePrice] => 95758.803 [basePriceVariant] => 95758.803 [basePriceWithTax] => 0 [discountedPriceWithoutTax] => 0 [priceBeforeTax] => 95758.803 [salesPrice] => 95758.803 [taxAmount] => 0 [salesPriceWithDiscount] => 0 [salesPriceTemp] => 95758.803 [discountAmount] => 0 [priceWithoutTax] => 95758.803 [variantModification] => 0 [DBTax] => Array ( ) [Tax] => Array ( ) [VatTax] => Array ( ) [DATax] => Array ( ) [subtotal] => 95758.803 [subtotal_tax_amount] => 0 [subtotal_discount] => 0 [subtotal_with_tax] => 95758.803 ) [shipmentValue] => 0 [shipmentTax] => 0 [shipmentTotal] => 0 [salesPriceShipment] => 0 [discountBeforeTaxBill] => 0 [withTax] => 210668.409 [discountAfterTax] => 210668.409 [paymentValue] => 0 [paymentTax] => 0 [paymentTotal] => 0 [salesPricePayment] => 0 [payment_tax_id] => 0 [cost] => 0 [billSub] => 210668.409 [billDiscountAmount] => 0 [billTaxAmount] => 0 [billTotal] => 210668.409 ) [pricesCurrency] => 153 [paymentCurrency] => 153 [_inCheckOut] => 1 [_dataValidated] => [_confirmDone] => [STsameAsBT] => 0 )
请注意:我是php新手,任何帮助都会非常好

数组是否需要循环以获得结果,还是我遗漏了什么


感谢阅读。

我认为您可以使用以下代码访问。但不确定

$amount = $array->products[0]->quantity

如果您显示您的
数组

运行
var\u dump($array)
并编辑问题以添加输出,这将非常有用。请参见上面的var_dump@MasterGray101你能不能
print\r($array)
并更新您的答案。您想让我给您打印结果吗?现在可以吗?我无法在我的问题中添加打印结果,因为我达到了最大正文限制-我是否应该删除变量转储结果并将其替换为打印?是的,将变量转储替换为打印
$amount = $array->products[0]->quantity