Php 数组值作为变量名

Php 数组值作为变量名,php,arrays,loops,Php,Arrays,Loops,我最近发现了另一个stackoverflow问题,如下所示: $segments = array( "key1" =>"111", "key2" =>"222", "key3" =>"333", "key4" =>"444" ); 我想要这些: $key1 has the value of "111"; $key2 has the value of "222"; $key3 has the value of "333"; $key4

我最近发现了另一个stackoverflow问题,如下所示:

$segments = array(
"key1"    =>"111",
"key2"    =>"222",
"key3"    =>"333",
"key4"    =>"444"
);
我想要这些:

$key1 has the value of  "111";

$key2 has the value of  "222";

$key3 has the value of  "333";

$key4 has the value of  "444";
答案是使用
提取($segments)

我想实现一些不一样的东西,我有以下数组

 $test = array('hello','world');
理想情况下,我希望遍历它们并使用数组值作为变量名,例如:

$test2 = array('hello','world');
foreach($test as $v)
{
   $$v = $v;
}
因此,在循环之后,我可以回显说
$hello
,这将导致输出
hello


有谁能告诉我如何才能做到这一点。如果有一种方法没有循环等等,那就太好了。我意识到我的例子可以做得不同,因此这个问题是多余的,但我问这个问题是出于好奇和我的知识。

数组更好,而且你很少需要
提取
或变量,但这是一种方法(仅为了知识):


我只是想知道这会有什么用处。你的代码正在运行。你为什么要找另一个answer@AdamChertiOP想要
提取(数组('hello','world'))
,但这不起作用。本质上,OP想要做
$hello='hello'$世界=‘世界’我知道,但他所做的循环是在做完美的工作,我想知道你是否需要为数组中的每个变量放入$test2,但我已经测试过了,显然没有,在数组中添加了一个新元素,并按预期工作。非常感谢您的回复,让我在mo等待。
$test2 = array('hello','world');
extract(array_combine($test2, $test2));