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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:18:00+00:00 2026-06-11T06:18:00+00:00

I am creating a faceted search, and I’m am trying to use array_intersect to

  • 0

I am creating a faceted search, and I’m am trying to use array_intersect to compare the arrays and find the inputs that match.

The problem is that I will have a variable amount of arrays at anytime depending on what filters the user has selected:

$array_1, $array_2, $array_3 etc…

How do I create an array_intersect function that is dynamic in this sense?

This is what I’ve tried:

$next_array = 0;
for($i = 0; $i < $array_count; $i++) {
    $next_array++;
    if ($i == 0) {
        $full_array = ${array_.$i};
    } else {
        if(!empty(${cvp_array.$next_array})) {
            $full_array = array_intersect($full_array, ${cvp_array_.$next_array});
        }
    }
}

————- EDIT ————-

I’ll try to narrow down my goal a bit more:

If the user clicks three filters, this results in three arrays being created with each having individual results:

Array_1 ( [0] => 2, [1] => 4, [2] => 6 )

Array_2 ( [0] => 1, [1] => 4, [2] => 6 )

Array_3 ( [0] => 6, [1] => 7, [2] => 8 )

I need code that will find the number that is in ALL of the arrays. And if there is no common number then it would end as false or something. In the case above, I’d need it to retrieve 6. If it was only the first two arrays, it would return 4 and 6.

  • 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-11T06:18:01+00:00Added an answer on June 11, 2026 at 6:18 am

    First of all, turn those arrays into an array of arrays. Then you can use array_reduce combined with array_intersect to reduce a variable amount of arrays down to one.

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

Sidebar

Related Questions

Creating a server-side socket will fail if I'm trying to use the same port
I am building a faceted search system that has inputs in a sidebar (the
Creating a patch utility that will update my current website with my patch. when
I'm working on a faceted search in Coldfusion and SQL. I've tried creating a
Creating a DIV that uses CSS to draw a triangle to the left. Trying
Creating an HTA that will automate the installation of several applications it starts by
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
Creating a simple RPG game, first time using XNA. Trying to get my character
i'm looking for some help in creating a faceted plot with angeled x-axis tick
Creating a calculator-like dialog, I noticed that quickly clicking on a button in IE

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.