/** * 添加缓存sessin数据 * @param $id 衣服id * @param $type 谁用 例:clothesVoid * @param $data 需要存在数据里的值 * @param $addess 需要存在数据里的值的位置 例:array('dd'=>array('kk'=>'da')),要将数据保存在二维数组kk下的写法 ('dd/kk') */ public static function SessionAdd($id = 0, $type = '', $data = '', $addess = '') { $id = trim($id); $type = trim($type); $addess = trim($addess); $data = trim($data); try { Comm::checkValue($id, 'ID', 1, 1); Comm::checkValue($type, '', 0, 1); Comm::checkValue($addess, '', 0, 1); Comm::checkValue($data, '', 0, 1); } catch (Exception $e) { return false; } $addess2 = explode('/', $addess); $json_data = ''; if ($id == 999999999) { $id = session_id(); } if (isset($_SESSION[$type . $id])) { $json_data = $_SESSION[$type . $id]; $json_data = trim($json_data); if (!empty($json_data)) { $json_data = json_decode($json_data, true); } } if (gettype($json_data) != 'array') { $json_data = array(); } $xb = array_pop($addess2); //去除数组最后一个元素 $json_data = json_encode(Comm::arrayAdd($json_data, $addess2, array($xb => $data))); $_SESSION[$type . $id] = $json_data; // echo $type.$id.'---'; // print_r($json_data);exit(); }