我有一个函数在帖子上接收字符串化的 json 对象。每次单击复选框时,我都希望将该数据添加到数组中。出于某种原因,当我单击多个复选框时,它只存储我单击的第一个数据。我究竟做错了什么?
public function add_to_composer() {
session_start();
$result = "1"; // maybe return 1 if the cdo was added into the session array, and -1 if it was deleted? just an idea
if(!isset($array))
{
$array = array($this->input->post());
$_SESSION['composer'] = $array;
}
else if(isset($array)) {
array_push($array, $this->input->post());
$_SESSION['composer'] = $array;
}
//$_SESSION['rep1']= json_encode($this->input->post(), true);
//array_push($_SESSION['composer'], $_SESSION['rep1']);
// add the cdo to the session array, or else remove it
var_dump($this->input->post());
}