When to use a variable variable in PHP?

后端 未结 8 1734
-上瘾入骨i
-上瘾入骨i 2021-01-03 03:49

I\'ve been developing in PHP for a while now, and I still have not had a task where I\'ve had to use variable variables. Can anyone give me examples where using them is a go

8条回答
  •  孤街浪徒
    2021-01-03 04:33

    First off, it'd be a huge security concern were you to use user output for these purposes. Internals are the only valid use here.

    Given that, I imagine it's for things like looping through various variables, or sending variables as parameters.

    foreach($name in array('_GET','_POST','_REQUEST')) {
        array_map('stripslashes',$$name);
    }
    

提交回复
热议问题