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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:56:57+00:00 2026-05-27T23:56:57+00:00

Given two arrays: $foo = array(‘a’, ‘b’, ‘c’); $bar = array(‘a’ => 1, ‘b’

  • 0

Given two arrays:

$foo = array('a', 'b', 'c');
$bar = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);

Is there a built-in PHP function to produce the following result array?

$result = array('a' => 1, 'b' => 2, 'c' => 3);

I’ve been through the Array Functions list on php.net, but can’t seem to find what I’m looking for. I know how to do it myself if need be, but I figured this might be a common-enough problem that there might be a built-in function that does it and didn’t want to reinvent the wheel.

  • 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-27T23:56:58+00:00Added an answer on May 27, 2026 at 11:56 pm

    Another way using array_flip and array_intersect_keys:

    $foo = array('a', 'b', 'c'); 
    $bar = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
    
    $common = array_intersect_key($bar, array_flip($foo));
    

    Output

    array(3) {
      ["a"]=>
      int(0)
      ["b"]=>
      int(1)
      ["c"]=>
      int(2)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following two indexed arrays: $a = array('a', 'b', 'c'); $b = array('red',
Given two sorted arrays: A and B . The size of array A is
There are two arrays, that are given for $link from foreach . One time
Given two arrays, is there a fast algorithm for finding all elements in the
Given a basic key/value array, I'm wanting to store two sorted arrays based on
Given an array like {one two, three four five}, how'd you calculate the total
Given two interface references obtained from different sources. Is there a programmatic way to
Given two arrays A[n] and B[m] , how can I find the smallest window
I am trying to get the text between two tag. <b> foo</b>bar<br/> => bar
Given two arrays as parameters (x and y) and find the starting index where

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.