2017-11-08 9 views
0

このセッションの行間をどのように反復して、私が欲しいものを得るのか分かりません。私はさまざまなアプローチを試みましたが、正しい結果を得られませんでした。テストのための PHPでネストされた配列を持つセッションの行をどのように反復するのですか?

foreach($this->session->data['cart'] as $key=>$row){ 
    $this->cart->add($row['product_id'], $row['quantity'], $row['option'], $row['recurring_id'], $row['store_id']); 
} 

ORこの:あらゆる種類の助けを

foreach($this->session->data['cart']['row'] as $key=>$row){ 
    print_r($row['product_id']); 
    print_r('<hr>');     
} 


Array 
(
     [num_rows] => 10 
     [row] => Array 
       (
         [cart_id] => 126 
         [product_id] => 45 
         [recurring_id] => 0 
         [option] => {"90":["263"],"89":["260"]} 
         [quantity] => 2 
         [store_id] => 2 
       ) 

     [rows] => Array 
       (
         [0] => Array 
           (
             [cart_id] => 126 
             [product_id] => 45 
             [recurring_id] => 0 
             [option] => {"90":["263"],"89":["260"]} 
             [quantity] => 2 
             [date_added] => 2017-11-08 21:19:56 
             [store_id] => 2 
           ) 

         [1] => Array 
           (
             [cart_id] => 127 
             [product_id] => 46 
             [recurring_id] => 0 
             [option] => {"90":["263"],"89":["261"]} 
             [quantity] => 1 
             [date_added] => 2017-11-08 21:19:56 
             [store_id] => 2 
           )... 

感謝します。

+0

@coderodour:同じことを。うまくいかなかった。 – Kardo

+0

$ this-> session-> data ['cart'] 'の代わりに '$ this-> session-> data [' cart '] [' rows ']'を試してください – JTC

答えて

1

$this->session->data['cart']はあなたがforeachループの後に提供さ配列が含まれている場合、あなたは、単にこれを行うことができます。

foreach($this->session->data['cart']['rows'] as $key => $row){ 
    $this->cart->add($row['product_id'], $row['quantity'], $row['option'], $row['recurring_id'], $row['store_id']); 
} 
+0

多くのありがとうございます!それは完璧に動作します:-) – Kardo

関連する問題