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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:15:40+00:00 2026-06-11T16:15:40+00:00

I was wondering if there is a native PHP function for returning an array

  • 0

I was wondering if there is a native PHP function for returning an array made up of of a certain set of given key=>value elements from another array, given a list of require keys. Here’s what I mean:

// Nice information
$source_array = array('a' => 'hello', 'b' => 'goodbye', 'c' => 'good day', 'd' => 'sunshine');

// Required element keys
$array_two = array('a','b');
$array_three = array('a','d');

// Get that stuff from $source_array...
// $array_two_result = ???
// $array_three_result = ???

// Show it
print_r($array_two_result);
print_r($array_three_result);

Outputs:

Array(
    [a] => 'hello'
    [b] => 'goodbye'
)
Array(
    [a] => 'hello'
    [d] => 'sunshine'
)

I’ve been looking through the documentation but can’t find anything as of yet, but it doesn’t seem to me like a particularly deviant thing to want to do, hence the question.

  • 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-11T16:15:41+00:00Added an answer on June 11, 2026 at 4:15 pm

    This seems to be what you are looking for: array_intesect_key

    $source_array = array('a' => 'hello', 'b' => 'goodbye', 'c' => 'good day', 'd' => 'sunshine');
    
    // Required element keys
    $array_two = array('a','b');
    $array_three = array('a','d');
    
    // Get that stuff from $source_array...
    $array_two_result = array_intersect_key($source_array, array_flip($array_two));
    $array_three_result = array_intersect_key($source_array, array_flip($array_three));
    
    // Show it
    print_r($array_two_result);
    print_r($array_three_result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if there is a python cognate to PHP's crypt() function that
I'm wondering if there is a way to access R class attribute from native
I was wondering if there is a native C++ (or STL/Boost) function which will
Wondering if there is any way to get the lambda expressions that result from
I was wondering if there is any way a native pointer can point to
I'm wondering if there are any good non-native form inputs for web development? I
While answering PHP rename() doesn't throws exception on error I was wondering if there
I was wondering if there is any downsides from using rvm in a production
I have an application I've written in PHP from scratch. I'm using PHP's native
I'm wondering if there really is no 128-bit division intrinsic function in Visual C++?

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.