php将变量转换为数组
I don't mind using arrays -- in fact, I love them. They're easy to use and hold collections of information well.
我不介意使用数组-实际上,我喜欢它们。 它们易于使用,并且可以很好地保存信息。
I don't always want to use arrays though. Why use:
我并不总是想要使用数组。 为什么使用:
echo $user['first_name'];
when you could simply use:
当您可以简单地使用:
echo $first_name;
So how can we get rid of the array part of the variables?
那么我们如何摆脱变量的数组部分呢?
代码 (The Code)
foreach($user as $key=>$value) { $$key = $value; }
//or....
foreach($user as $key=>$value) { ${$key} = $value; }
A few variables you must be careful with are:
您必须注意的一些变量是:
$_GET
$ _GET
$_POST
$ _POST
$_REQUEST
$ _REQUEST
Why? Because $_GET, $_POST, and $_REQUEST variables can manipulated by the user and that would present a huge security concern.
为什么? 因为$ _GET , $ _POST和$ _REQUEST变量可以由用户操纵,这将带来巨大的安全隐患。
翻译自: https://davidwalsh.name/convert-key-value-arrays-standard-variables-php
php将变量转换为数组