如何在codeigniter中获取多个ID产品购物车

时间:2017-09-18 03:59:41

标签: php mysql codeigniter

我的购物车中有两件商品。我想以数组的形式显示ID,我试过但结果是:

Array ( [0] => Array ( [idp] => 11 ) [1] => Array ( [idp] => 9 ) )

我想要结果:

array(11,9)

我的控制员:

foreach($this->cart->contents() as $items):
                        $data_product_stock[] = array(
                            'idp'   => $items['id'],
                        );
                    endforeach;
                    print_r($data_product_stock);

2 个答案:

答案 0 :(得分:0)

你可以像这样创建数组

 foreach($this->cart->contents() as $items):
                            $data_product_stock[] =  $items['id'];
                        endforeach;
                        print_r($data_product_stock);

答案 1 :(得分:0)

试试这个

array_column($data_product_stock, 'idp');

它会给出ids数组,但请记住$data_product_stock应为数组