简体   繁体   English

如何在Codeigniter中获得多个ID产品购物车

[英]how to get multiple ID product cart in codeigniter

i have two product in my cart. 我的购物车中有两个产品。 and I want to display the ID in the form of an array, I have tried but the result : 我想以数组的形式显示ID,我试过但结果是:

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

i want the result : 我想要结果:

array(11,9)

my controller : 我的控制器:

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

you can create array like this 你可以像这样创建数组

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

Try This 尝试这个

array_column($data_product_stock, 'idp');

It will give array of ids but remember $data_product_stock should be array 它将给出ids数组,但请记住$data_product_stock应该是array

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM