将“do_action”插入到特定索引处的数组中(PHP)
问题描述:
有没有人能够将do_action的输出插入到特定索引的数组中?举例来说,如果你有下面的数组和功能:将“do_action”插入到特定索引处的数组中(PHP)
$myarr = array(1,2,3,4);
my_function(){
return 4 + 4;
}
我试图做的事:
array_splice($myarr, 2, 0, do_action('my_function'););
而且有它的输出:
[1, 2, 8, 3, 4]
我想在wordpress页面中整合了这样的内容,并且它打破了我的整个页面。
答
如果这是你确切的代码,那么问题就在这里
array_splice($myarr, 2, 0, do_action('my_function'););
正确的路线是
array_splice($myarr, 2, 0, my_function());
另外,'function'关键字从创建my_function声明的开始丢失了。 –