when you run setcookie and print cookie in a same page, before the setcookie command is transport to browser, to make the print command, PHP will get the cookie value from browser first, so you will get the earlier cookie value.
如果你在同一个页面运行setcookie和打印cookie的命令,PHP会先从客户端取得cookie的值,然后将这个html文件发送到客户端,在这个html文件中才包含了setcookie的命令,所以你得到的cookie的值是上一次的值。