is it possible if callback in array_filter receive parameter ?

Posted by justjoe on Stack Overflow See other posts from Stack Overflow or by justjoe
Published on 2010-03-27T14:59:58Z Indexed on 2010/03/27 15:03 UTC
Read the original article Hit count: 246

i got this multiple array name $files[], who consist keys and values as below :

    [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
        )

and i use this code to create new array consist of 'name' keys only. but it failed

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

    function is_inarr_key($array, $key) {

  //TODO : remove every array except those who got the same $key
    }

and i got this error

array_filter() [function.array-filter]: The second argument, 'is_inarr_key('name')', should be a valid callback in C:\xampp\htdocs\php\gettingstarted\index.php on line 15

so the queastion : 1. is it possible to make call-back function on array_filter has ability to receive parameter ?

  1. What is general rule of thumb on how to use callback in anyPHP built-in function ?

© Stack Overflow or respective owner

Related posts about php

Related posts about multidimensional-array