I got this multiple array named $files[], which consists of keys and values as below:
[
[
'name' => 'index1.php',
'path' => 'http://localhost/php/gettingstarted/',
'number' => 1,
],
[
'name' => 'index10.php',
'path' => 'http://localhost/php/gettingstarted/',
'number' => 2,
],
[
'name' => 'index11.php',
'path' => 'http://localhost/php/gettingstarted/',
'number' => 3,
],
]
I use this code to create a 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 get 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 my questions are:
- Is it possible to make the call-back function on
array_filterreceive parameter? - What is the general rule of thumb on how to use callback in any PHP built-in function?
nameor are you filtering rows which contain a specific value in thenamecolumn or are you wanting to isolate the values in thenamecolumn as a new array? ThatI use this code to create a new array consist of 'name' keys only.sentence makes me believe it is the third one. In which case, you don't needarray_filter(), you wantarray_column(). This question may be an XY Problem.