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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:28:40+00:00 2026-05-23T00:28:40+00:00

all I have a bundle of data like 1, 2, 3, 4, 5, 6,

  • 0

all

I have a bundle of data like 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

then I separate these data into 2 groups which is

$groupA = range(1, 5)

$groupB = range(6, 10)

For instance, I have $data = array(1, 4) and it will return this belong to Group A. Likewise,
$data = array(7,8), it will return to me Group B.

So how can I write a script to let $data = array(1, 4, 6, 7) return me Group A and Group B?

Thank you

  • 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-23T00:28:41+00:00Added an answer on May 23, 2026 at 12:28 am

    You may want to use array_intersect:

    $groupA = range(1, 5);
    $groupB = range(6, 10);
    $data = array(1, 4, 6, 7);
    $foundGroups = array();
    if(array_intersect($data, $groupA))
        $foundGroups[] = 'A';
    if(array_intersect($data, $groupB))
        $foundGroups[] = 'B';
    print_r($foundGroups);
    

    Note that an empty array evaluates to false while one with at least one element evaluates to true.

    Warning: If you have to work with a lot of groups with many elements you may want to use a manual approach and stop at the first common element found. array_intersect finds all the common elements and you don’t really need that.

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

Sidebar

Related Questions

I have a rake task that looks like so (crontab): cd /data/TheApp/current && bundle
i have all my students data in s variable i.e first name,last name,id. which
I have created a bunch of movie clips which all have similar names and
I have some tables. These tables all have one column in common called 'classified_id':
I am working in one application in which I have to fetch all the
I have three classes that all have a static function called 'create'. I would
I'm sure we all have received the wonderfully vague Object reference not set to
I have a bunch of projects in parallel subdirectories that all have etc/lighttpd.conf files.
I have a MFC dialog with 32 CComboBoxes on it that all have the
I have a database with Points of Interest that all have an address. I

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.