【问题标题】:Insert "do_action" into an array at a specific index (PHP)将“do_action”插入到特定索引处的数组中(PHP)
【发布时间】:2017-02-11 23:07:36
【问题描述】:

有没有人能够将 do_action 的输出插入到特定索引处的数组中?例如,如果你有下面的数组和函数:

$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 页面中,但它破坏了我的整个页面。

【问题讨论】:

    标签: php arrays wordpress splice


    【解决方案1】:

    如果那是您的确切代码,那么问题就在这里

    array_splice($myarr, 2, 0, do_action('my_function'););
    

    正确的行是

    array_splice($myarr, 2, 0, my_function());
    

    【讨论】:

    • 此外,my_function 声明的开头缺少 function 关键字。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-08
    • 2010-10-09
    • 2015-08-11
    • 2020-07-24
    • 2019-11-20
    • 2015-11-08
    相关资源
    最近更新 更多