gpt4 book ai didi

php - 使我的函数在当前范围内设置变量

转载 作者:可可西里 更新时间:2023-11-01 01:06:06 24 4
gpt4 key购买 nike

可以吗?

function my_function(&$array){

// processing $array here

extract($array); // create variables but not here
}

function B(){

$some_array = array('var1' => 23423, 'var2' => 'foo');

my_function($some_array);

// here I want to have $var, $var2 (what extract produced in my function)
}

例如 parse_str() 能够做到这一点。

最佳答案

编辑 在我的第一个回答中没有考虑。

答案是否定的;您可以将 extract 调用移动到您的函数 B 中,仅此而已。

顺便说一句,有了更多关于你的问题的背景知识,我可以改进我的回答:)

关于php - 使我的函数在当前范围内设置变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10656118/

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