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

  • Home
  • SEARCH
  • 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 5973593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:49:18+00:00 2026-05-22T20:49:18+00:00

I know this is probably a very simple question but I have looked around

  • 0

I know this is probably a very simple question but I have looked around and most answers relate to array intersections which is not what I am looking for.

Example:

I have an array ($rows). When running print_r($rows) I get:

Array (
  [0] => Array (
    [id] => 184
    [0] => 184
    [name] => Advantage Membership
    [1] => Advantage Membership
    [flag] => 4
    [2] => 4
  )
  [1] => Array (
    [id] => 238
    [0] => 238
    [programname] => Package 2
    [1] => Package 2
    [flag] => 5
    [2] => 5
  )
) 

I want to essentially create a ‘sub’ array which contains all of the ‘flag’ fields in my $rows array so that I can THEN do a if(in_array()) statement with another value.

ideal result array would look like:

$array2 = array( '4', '5' )

Then I could run the following and be happy:

if (in_array(4, $array2)) ...

Any suggestions?

  • 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-22T20:49:19+00:00Added an answer on May 22, 2026 at 8:49 pm

    What’s wrong with a custom function?

    function in_sub_array($needle, $ary){
      foreach ($ary as $a){
        if (isset($a['flag']) && $a['flag'] == $needle) // could use ===, too.
          return true;
      }
      return false;
    }
    
    if (in_sub_arry(4,$array2)) ...
    

    Or, as others have suggested, array_map is a good alternative.

    function get_flags($ary){
      return (isset($ary['flag']) ? $ary['flag'] : null);
    }
    
    if (in_array(4,array_map('get_flags',$array2))) ...
    

    demos of both methods

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

Sidebar

Related Questions

I know this is probably a very simple question but how would I do
This is probably a very simple question but I have a confusion about the
I know this is probably a very simple question, but I can't seem to
Okay, this is probably very simple but, I have the below checks (not at
This is probably a very simple question. I am new to Rails and have
This is probably an overly simple question, but I have a blog Creating Wealth
This is probably a very simple question for somebody with experience, but I just
This probably seems like a very simple question, and I would probably know if
Most of you will probably label this is a very generic question, but still,
I know this probably really simple but Im not sure what im doing wrong...

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.