PHP创建Cookie数组的简单范例

PHP中创建Cookie数组的方法,几个小例子。

创建cookie数组:
<?php
setcookie("ICNet[Reg]", "This is reg cookie", time() + 3600);
setcookie("ICNet[Active]", "This is login cookie.", time() + 3600);
print_r($_COOKIE);

/*Result:
Array (  [ICNet] => Array ( [Reg] => This is reg cookie [Active] => This is login cookie ) [PHPSESSID] => nsi2q5upuvqrik6notaohjd7p3 ) 
*/
//by www.jbxue.com
?>


读取cookie数组中的值:
<?php
echo $_COOKIE['ICNet']['Reg'];
echo $_COOKIE['ICNet']['Active'];
//或者
$arr_cookie = $_COOKIE['ICNet'];
echo $arr_cookie['Reg'];
echo $arr_cookie['Active'];
//modify by www.jbxue.com
?>


销毁cookie数组的值:
<?php
//edit by www.jbxue.com
setcookie('ICNet[Reg]', '', time() - 3600);
setcookie('ICNet[Active]', '', time() - 3600);
?>

你可能感兴趣的:(数组,cookie,读取,销毁)