相关疑难解决方法(0)

如果array_filter中的回调接收参数可能吗?

我得到了这个多个数组$files[],它由键和值组成,如下所示:

[0] => Array
(
    [name] => index1.php
    [path] => http://localhost/php/gettingstarted/
    [number] => 1
)

[1] => Array
(
    [name] => index10.php
    [path] => http://localhost/php/gettingstarted/
    [number] => 2
)

[2] => Array
(
    [name] => index11.php
    [path] => http://localhost/php/gettingstarted/
    [number] => 3
)
Run Code Online (Sandbox Code Playgroud)

我使用此代码创建一个仅由'name'键组成的新数组.但它失败了

array_filter($files, "is_inarr_key('name')");

function is_inarr_key($array, $key)
{
    //TODO : remove every array except those who got the same $key
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

array_filter()[function.array滤波器]:第二个参数, 'is_inarr_key(' 姓名 ')',应该在C有效的回调:\ XAMPP\htdocs中\ PHP\gettingstarted \第15行的index.php

所以我的问题是:

  1. 是否可以在array_filter接收参数上进行回调功能?
  2. 关于如何在任何PHP内置函数中使用回调的一般经验法则是什么?

php arrays multidimensional-array

13
推荐指数
1
解决办法
2万
查看次数

标签 统计

arrays ×1

multidimensional-array ×1

php ×1