admin管理员组文章数量:1336632
i am trying to get array in filters in wordpress i dont khnow how to do it.
add_filter('ft_tabs', function ($tabs) {
return array_push($tabs, array(
'111' => 'aaa',
'222' => 'bbb'
));
}, 10);
add_filter('ft_tabs', function ($tabs) {
return array_push($tabs, array(
'333' => 'ccc',
'444' => 'ddd'
));
}, 15);
$array = array();
$asdasd = apply_filters('ft_tabs', $array);
i am trying to get array in filters in wordpress i dont khnow how to do it.
add_filter('ft_tabs', function ($tabs) {
return array_push($tabs, array(
'111' => 'aaa',
'222' => 'bbb'
));
}, 10);
add_filter('ft_tabs', function ($tabs) {
return array_push($tabs, array(
'333' => 'ccc',
'444' => 'ddd'
));
}, 15);
$array = array();
$asdasd = apply_filters('ft_tabs', $array);
Share
Improve this question
edited Jul 20, 2020 at 2:40
mozboz
2,6281 gold badge12 silver badges23 bronze badges
asked Jul 19, 2020 at 13:55
saeedsaeed
32 bronze badges
1 Answer
Reset to default 1Note this is mostly a PHP programming question about arrays and is better asked on e.g. Stack Overflow.
As shown in the docs array_push()
acts on the array and takes multiple parameters which get added as array values. It doesn't add key => value pairs to associative arrays, and it doesn't return the array itself, so you're probably looking for array_merge
or just the +
operator, then returning the new value e.g.
add_filter('ft_tabs', function ($tabs) {
$tabs = $tabs + arrary(
'111' => 'aaa',
'222' => 'bbb'
);
return $tabs;
}, 10);
Also it's poor style to use reserved words like 'array' for variables names as you risk confusing the interpreter and getting a very unexpected result such as calling the array
function when you meant to get the value of a variable.
本文标签: phpHow to append to an array and return the results in a filter
版权声明:本文标题:php - How to append to an array and return the results in a filter? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742248897a2440375.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论