2013-02-18 57 views
-2

傾銷會話後,我得到下面的結果。任何人都可以告訴我如何獲得數組(2)中的「product_id」和「info」的值;獲取數組值

array(3) { 
    ["DYN_outskin"]=> string(3) "ten" 
    ["DYN_inskin"]=> string(3) "one" 
    ["cart"]=> array(1) { 
     ["2000_facebook"]=> array(2) { 
      ["product_id"]=> string(13) "2000_facebook" 
      ["info"]=> string(7) "nur1952" 
     } 
    } 
} 
+0

路徑陣列 - > [2000_facebook] - > [車] - > [PRODUCT_ID]然後$改編[2000_facebook] [cart] [product_id] – 2013-02-18 18:28:37

+0

@ gd1:我得到了這個結果,它是session的print_r ======================= Array([DYN_outskin] => ten [DYN_inskin] => one [cart] => Array([2000_facebook] => Array([product_id] => 2000_facebook [info] => nur1952)[web_traffic] => Array([product_id] => web_traffic [info] = > fbmuseum.com))) – Nur 2013-02-18 18:30:38

+4

http://php.net/arrays – knittl 2013-02-18 18:30:52

回答

2

嘗試這樣的:在購物車

$array['cart']['2000_facebook']['product_id']; 
$array['cart']['2000_facebook']['info']; 
+0

你能幫我解答嗎?它是顯示foreach循環==============================存儲的會話數據\t \t \t \t \t \t <?PHP \t \t \t //添加項到購物車 \t \t \t $ _SESSION [ '購物'] [$ git_product_id] =陣列( 'PRODUCT_ID'=> $ git_product_id, '信息'=> $ git_required); ? \t \t \t> \t \t \t \t \t \t $鍵):> \t \t \t \t \t \t //這裏展示的product_id和信息 \t \t \t <?php endforeach; ?> – Nur 2013-02-18 18:40:22

+0

當然我可以幫忙,但是請將您的代碼粘貼到urloment.com或pastebin.com ..謝謝 – 2013-02-18 18:50:39

2
$_SESSION["cart"]["2000_facebook"]["product_id"] ; 

$_SESSION["cart"]["2000_facebook"]["info"] ; 

迭代:

foreach ($_SESSION["cart"] as $product){ 
    echo "Product info : {$product['info']} | Product ID : {$product['product_id']} <br/>" ; 
} 
+0

很棒!!!!!!!!!!!!你已經救了我24小時。謝謝,謝謝! – Nur 2013-02-18 18:45:15

+0

沒有probs :)接受,但如果你覺得它有用。 – vikingmaster 2013-02-18 18:46:54

1

它始終是一個很好的做法,以顯示清楚顯示陣列的方式排列結構如下:

array(3) { 
    ["DYN_outskin"]=> string(3) "ten" 
    ["DYN_inskin"]=> string(3) "one" 
    ["cart"]=> array(1) { 
    ["2000_facebook"]=> array(2) { 
     ["product_id"]=> string(13) "2000_facebook" 
     ["info"]=> string(7) "nur1952" 
    } 
    } 
} 

現在,它清楚你如何訪問需要的元素:

$array["cart"]["2000_facebook"]["product_id"] 
$array["cart"]["2000_facebook"]["info"]