2013-02-18 60 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"]