gpt4 book ai didi

php - 从键值数组 PHP 设置变量

转载 作者:可可西里 更新时间:2023-11-01 00:03:45 26 4
gpt4 key购买 nike

我有一个数组:

array(
'myVar1' => 'value1',
'myVar2' => 'value1',
'myVar3' => 'value3',
);

PHP 中是否有一个内置函数可以生成 3 个变量,例如$myVar1、$myVar2、$myVar3 在我 echo $myVar1; 时执行此操作,它返回 'value1'

显然我可以循环数组并相应地设置它们(所以请不要回答这个问题),但是如果有一个内部 PHP 函数那就太好了!

最佳答案

extract()是函数:

Import variables into the current symbol table from an array...

Checks each key to see whether it has a valid variable name. It also checks for collisions with existing variables in the symbol table...

关于php - 从键值数组 PHP 设置变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6524414/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com