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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:28:23+00:00 2026-06-09T06:28:23+00:00

I feel really stupid right now since I can remember doing something like this.

  • 0

I feel really stupid right now since I can remember doing something like this. But now my head is empty and this really seems to look like a problem.

I have two arrays. First:

array (
  0 => 
  array (
    'id' => '1',
    'name' => 'Blizzard',
    'slug' => 'blizzard',
  ),
  1 => 
  array (
    'id' => '2',
    'name' => 'Id Software',
    'slug' => 'id-software',
  ),
  2 => 
  array (
    'id' => '3',
    'name' => 'Capcom',
    'slug' => 'capcom',
  ),
  3 => 
  array (
    'id' => '4',
    'name' => 'Maxis',
    'slug' => 'maxis',
  ),
  4 => 
  array (
    'id' => '5',
    'name' => 'Electronic Arts',
    'slug' => 'electronic-arts',
  ),
)

And secound one:

array (
  0 => '3',
  1 => '4',
)

What I want to do is, take value from the secound array and match it with the value of the first one. How can I do this?

  • 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-09T06:28:24+00:00Added an answer on June 9, 2026 at 6:28 am

    When you say “by value”, I’m assuming you meant by id value, in which case, if you already know that the id value is one less than the key, you can do this:

    foreach( $second as $id) {
        $key = $id - 1;
        $row = $first[ $key ];
        echo $row['name'];
    }
    

    Otherwise, you’ll have to loop / search for the specific id:

    foreach( $second as $id) {
        foreach( $first as $row) {
             if( $row['id'] == $id) {
                  echo $row['name']; break;
             }
        }        
    }
    

    However, another trick you can use to just get an array containing the elements you want is to use array_filter(), like so:

    $second = array( 3, 4);
    $keep = array_filter( $first, function( $el) use( $second) { 
        return in_array( $el['id'], $second); 
    }); 
    

    Now $keep will contain an array of the two values you want, and you can loop over them accordingly.

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

Sidebar

Related Questions

I feel like I must be doing something really stupid. What can I do
I feel really stupid for asking a question like this, but I cannot seem
I feel really stupid asking for this, but remarkably I'm banging my head for
I feel really stupid right now. The following code should output 'If you can
I really feel stupid for posting this but since i got no answers on
Ok, I feel like this is a really stupid question, but I've been trying
I suspect I am going to feel really stupid after posting this but here
I apologize for the stupid question, but I feel like I've really struck a
Ok I feel really dumb asking this but I seem to be missing something
I feel like this might be really simple but I'm just not getting it

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.