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 8506711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:39:56+00:00 2026-06-11T02:39:56+00:00

I found an excellent tutorial on how to filter a Multidimensional array here: PHP

  • 0

I found an excellent tutorial on how to filter a Multidimensional array here:
PHP filter 2 dimensional array by specific key

While

$filtered = array_filter(
    $array, 
    function($v) { 
        return $v['type'] == 'folder'; 
    }
); 

does do exactly what I need in terms of only displaying the folder entries, I need to be able to filter the array based on user input.

So from the example used on the page I lised above, there would be a checkbox for folder, and for page, then depending on what the user chooses (page, folder, or both), their selection would be displayed.

The problem I am running into is that I can’t seem to use a variable to store $v[‘type’] == ‘folder’.

I am hoping to do something like:

$filtered = array_filter($array, function($v) { return $userSelections; });

I also explored the possibility of using eval() (I know it may not be the best idea, but I’ve tried everything else I can think of) to provide the contents of the variable, but that doesn’t seem to work either.

Any advice here would be great.

Thanks.

  • 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-06-11T02:39:58+00:00Added an answer on June 11, 2026 at 2:39 am

    That’s probably because of the variable scope inside closures. Try something like the following:

    $filtered = array_filter($array, 
        function($v) use ($userinput) { 
            return in_array($v['type'], $_POST['userSelections']); 
        }
    );
    

    With use you declare an outside variable as accessible from inside the closure – You make it “global” so to say.

    Edit: I included the final solution from below.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just finished going through the MvcMusicStore tutorial found here . It's an excellent
My registering here is a strong testimony to the excellent answers I've found here
Found this while reading the Neo4j manual, specifically here , I found the sentence:
Having found a seemingly excellent solution for loading images after a document's loaded here
I found an excellent tutorial on how to create site columns and content types
I have found this excellent tutorial on this topic, yet it leaves some open
Working through the excellent tutorial by David Powers , about setting up a php
I have been using this excellent decorator for memoization, which I found on the
I found the book Java Concurrency in Practice to be an excellent guide to
Update below... Ok, ive got a problem here. Im using this excellent vimeo class

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.