How to unset global variables.

时光毁灭记忆、已成空白 提交于 2019-12-23 15:05:11

问题


I have an id of a project and an id of a client that are sessions in php that are passed in JSON format. These are stored in global variables id_p and id_c so I can do multiple inserts and updates selects etc. with those ids.

When the user selects another project or changes the page, I need to unset these variables.

  • Can I pass a null value from php to the global vars to reset them?
  • Is there a better way to do what I want?
  • How could I store the php values on php only if the file is required? The files where the queries take place are on separate files.

回答1:


Would setting them to null or undefined accomplish what you're looking for?

id_p = null;
id_c = null;



回答2:


To really unset them, use

unset ( $GLOBALS['id_p'] );

This also works in functions.

Source: http://toscho.de/2012/php-unset-unterschied-global-globals/



来源:https://stackoverflow.com/questions/8622159/how-to-unset-global-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!