PHP-了解create_function()-传递简单变量 [英] Php - understanding create_function() - passing simple variable
问题描述
我第一次尝试使用动态create_function
,到目前为止,还没有太大的成功:-)
First time I am trying to use the dynamic create_function
, and up to now, not much success :-)
我的功能是这样的:
function o99_brsa_custom_widgets() {
global $wp_meta_boxes;
global $o99_brsa_options;
for($i=0; $i> count($o99_brsa_options[content]); $i++) {
$widgt_id = 'o99_dashboard_widget_dyn' . $i;
$widgt_name = 'obmek99 widget name' . $i;
$out = $o99_brsa_options[content][$i];
$f = create_function(' $out ',' global $out; echo $out;');
do_the_widgets($widgt_id, $widgt_name, $f);
}
}
do_the_widgets()
操作仅接受直接回显并打印窗口小部件的内容.
The do_the_widgets()
action is accepting only a direct echo and prints the content of the widget.
$o99_brsa_options[content]
是具有$i
个元素(每个都是内容)的经过验证的数组.
The $o99_brsa_options[content]
is a verified array with $i
elements (each is content) .
奇怪的是,$i
在$widgt_id
和$widgt_name
上都起作用,但是在create_function()
上,我在所有小部件上都打印了相同的值. (echo $out
)
The strange thing is that the $i
is working on the $widgt_id
and $widgt_name
but on the create_function()
I get the same value printed in all widgets . ( echo $out
)
似乎我不知道如何将一个简单的变量传递给新函数(我正在create_function()中使用global,但是到目前为止,它的作用不大.
It seems that I do not know how to pass a simple variable to the new function ( I am using global inside create_function(), but it helps little as for now .
那么,我现在的错误/误解/误用是什么:-) ??
So, what is my mistake / misunderstanding / misuse now :-) ??
推荐答案
create_function
在stone age
期间,当佩哈(PeeHaa埽)喝了啤酒,因为他写了hello would
,现在世界变得更好了,请使用closures
create_function
was during the stone age
, when kaᵠ used pen and paper to write applications, when PeeHaa埽 got a beer because he wrote hello would
, The world is better now please use closures
$f = function ($out) {
echo $out;
};
$f("Welcome");
有一天我要感谢我,但是如果您是 Gordon (过去寄来的机器在这里折磨我们),他是这样写的
You would thank me one day, But you can only use create_function
if you are Gordon (The machine from the past sent here to torment us) he wrote this
$fn = create_function(
'$x',
'return $x; } $foo = 42; function foo($int) { return $int; '
);
这篇关于PHP-了解create_function()-传递简单变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!