我正在开发一个codeigniter网站。这是我的控制器功能:
public function hoteldetails($id)
{
$this->load->helper('cookie');
$hotel_details_view = array();
$hotel_details_view = get_cookie('hotel_details_view');
array_push($hotel_details_view, $id);
$this->input->set_cookie($hotel_details_view);
print_r($hotel_details_view);
$this->load->view('hotel_details',$data);
}
现在我想在函数调用
时在cookie中设置多个$ id我收到错误:
遇到PHP错误
严重性:警告
消息:array_push()期望参数1为数组,布尔值为
文件名:controllers / hotel.php
行号:191
我需要帮助:))
答案 0 :(得分:1)
更新:试试这个:
public function hoteldetails($id)
{
$this->load->helper('cookie');
$hotel_details_view = array();
$cookieValue = get_cookie('hotel_details_view');
$hotel_details_view[] = $cookieValue;
$hotel_details_view[] = $id;
$this->input->set_cookie($hotel_details_view);
print_r($hotel_details_view);
$this->load->view('hotel_details',$data);
}
$hotel_details_view
数组将覆盖您从$hotel_details_view
获得的get_cookie()
字符串值。
答案 1 :(得分:0)
with open('file.txt') as f:
lines = f.read().splitlines()
com_and_url = (lines[i:i+2] for i in range(0, len(lines), 2))