2010-05-12 80 views
2

我想訪問smarty數組中的變量。該數組稱爲產品幷包含大量值。該陣列的print_r的轉儲如下所示在Smarty數組中訪問變量

Array 
(
    [0] => Array 
     (
      [itemid] => 4 
      [productid] => 31 
      [productcode] => 1658303 
      [product] => ENERGIZER 628504 COMP RECHARGABLE TORCH 
      [provider] => master 
      [distribution] => 
      [weight] => 0.00 
      [list_price] => 29.80 
      [descr] => Torches 
      [fulldescr] => Energizer Rechargeable Emergency Torch Complete With Krypton Bulb 
      [avail] => 6 
      [rating] => 2 
      [forsale] => Y 
      [add_date] => 0 
      [views_stats] => 1 
      [sales_stats] => 0 
      [del_stats] => 0 
      [shipping_freight] => 0.00 
      [free_shipping] => N 
      [discount_avail] => Y 
      [min_amount] => 1 
      [length] => 0.00 
      [width] => 0.00 
      [height] => 0.00 
      [low_avail_limit] => 10 
      [free_tax] => N 
      [product_type] => N 
      [manufacturerid] => 0 
      [return_time] => 0 
      [keywords] => 
      [meta_description] => 
      [meta_keywords] => 
      [small_item] => N 
      [separate_box] => N 
      [items_per_box] => 1 
      [title_tag] => 
      [orderid] => 2 
      [price] => 11.96 
      [amount] => 2 
      [product_options] => 
      [extra_data] => Array 
       (
        [product_options] => 
        [taxes] => Array 
         (
         ) 

        [display] => Array 
         (
          [price] => 11.96 
          [discounted_price] => 23.92 
          [subtotal] => 23.92 
         ) 

       ) 

      [is_deleted] => 
      [returns] => 
      [extra_fields] => Array 
       (
        [0] => Array 
         (
          [fieldid] => 1 
          [provider] => master 
          [field] => ESW Carbon Points 
          [value] => 50 
          [active] => Y 
          [orderby] => 1 
          [service_name] => SERVICE_NAME01 
          [productid] => 31 
         ) 

       ) 

      [display_price] => 11.96 
      [display_discounted_price] => 23.92 
      [display_subtotal] => 23.92 
      [product_options_txt] => 
      [ordered_price] => 11.96 
      [original_price] => 11.96 
      [price_deducted_tax] => Y 
     ) 

) 

我想額外的領域陣列內訪問「價值」的領域,但我不明白的語法是得到它的。

任何幫助非常感謝。

回答

1
{$var[0].extra_fields[0].value} 
+0

你寫的是什麼讓我感覺良好,我相信它會正常工作,但它不適合我。我認爲這與我正在使用的應用程序的處理方式有關,我在print_r之間​​和我試圖輸出變量之間處理smarty變量。 無論如何,您建議的解決方案確實讓我走上了正確的軌道,讓事情順利進行,我只是試圖以一種過於複雜的方式處理它。那謝謝啦! – bradfields 2010-05-12 14:09:56

0

{$var.0.extra_fields.0.value}