开发者

export array key and value as variable name and value

considering this array :

$segments = array(
    "key1"   开发者_高级运维 =>"111",
    "key2"    =>"222",
    "key3"    =>"333",
    "key4"    =>"444"
);

I want to have these:

$key1 has the value of "111";

$key2 has the value of "222";

$key3 has the value of "333";

$key4 has the value of "444";

What can I do ?


PHP has a built-in function that does exactly this:

extract($segments);

http://php.net/manual/en/function.extract.php


use

extract($segments)

References:

  • extract Extract the keys of an hash array into the corresponding variables
  • compact Does the reverse thing
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜