PHP: Using spaces in associative array indices

前端 未结 4 829
故里飘歌
故里飘歌 2021-01-04 01:59

Is this bad practice/can cause problems?

$_SESSION[\'stuff to keep\']

As opposed to calling str_replace() on the indices.

4条回答
  •  离开以前
    2021-01-04 02:29

    You can do that, it'll work -- and even if I don't generally do it when I set the keys of my arrays "by hand", it sometimes happens when I get the keys from a file (for instance), and I've never had any problem with this.

    Maybe this could cause some kind of a problem if you are using the extract functions, though. If it creates variables with spaces in their names (don't know if it will) it'll be difficult (but not impossible) to access your variables.

提交回复
热议问题