我想在两个 CodeIgniter 函数之间发送数据

I want to send data between two CodeIgniter function

我必须将值从一个函数传递到另一个函数..

我写的第一个函数是这样的。

function test1(){
        $product_details[] = array(
            'product_id' => '1',
            'count'      => '2'
        );
        $this->test2($product_details);
}    

第二个函数我是这样写的。我必须保留这个 $_POST 必须。

function test2(){
        $product_details = $_POST['product_details'];
        foreach($product_details as $row){
            $this->db->insert('table',$row);
        }
}

它甚至不打印发布的结果.. 提前致谢..:)

如果你想将数据从 test1 传递到 test2,就像在 test1 中一样

function test1()
{
    $product_details[] = array(
        'product_id' => '1',
        'count'      => '2'
    );
    $this->test2($product_details); # here you are trying to pass the $product_details to test2
}    

test2 的签名必须反映:

function test2(array $product_details) # this is the function signature
{
    $product_details = $_POST['product_details']; # this line would currently override your $product_details even if you passed them from test1
    $product_details[] = $_POST['product_details']; # maybe this is what you meant?
    foreach($product_details as $row){
        $this->db->insert('table',$row); # I imagine you tried echo $row or var_dump($row) here before?
    }
}