Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 699485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:23:29+00:00 2026-05-14T03:23:29+00:00

I got this multiple array named $files[] , which consists of keys and values

  • 0

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:

  1. Is it possible to make the call-back function on array_filter receive parameter?
  2. What is the general rule of thumb on how to use callback in any PHP built-in function?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:23:30+00:00Added an answer on May 14, 2026 at 3:23 am

    You can create a closure on PHP ≥5.3.

    array_filter($files, function($array) use ($key) {
      return is_inarr_key($array, $key); 
    } );
    

    If you are stuck with PHP <5.3, …

    You can make $key a global variable.

    function is_inarr_with_global_key($array) {
       global $key;
       ....
    }
    

    You can create a class

    class KeyFilter {
      function KeyFilter($key) { $this->key = $key; }
      function is_inarr_key($array) { ... }
    }
    ...
    array_filter($files, array(new KeyFilter('name'), 'is_inarr_key'));
    

    You can create 3 different functions

    array_filter($files, 'is_inarr_name');
    array_filter($files, 'is_inarr_path');
    array_filter($files, 'is_inarr_number');
    

    You can write your own array_filter

    function my_array_filter($files, $key) {
      ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this nasty problem where sending multiple, large messages in quick succession from
I got this síngleton cache object and it exposes an IEnumerable property which just
I've got this HTML form where I have multiple input elements: text, radio, and
I've made a field using Custom Formatters (Drupal, CCK). Now I got this PHP
I've got multiple access logs in the logs directory, following the naming convention below:
I got this error today when trying to open a Visual Studio 2008 project
I got this output when running sudo cpan Scalar::Util::Numeric jmm@freekbox:~/bfwsandbox/sa/angel/astroportal/dtu8e/resources$ sudo cpan Scalar::Util::Numeric [sudo]
I got this flash application where you can click a link while watching a
I got this error when I tried to compile an application that includes the
I got this bad feeling about how I insert larger amounts of HTML. Lets

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.