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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:40:53+00:00 2026-06-16T00:40:53+00:00

I have a array list (for this example I’m using cell phones). I’m wanting

  • 0

I have a array list (for this example I’m using cell phones). I’m wanting to be able to search for multiple key/value pairs and return it’s parent array index.

For example, here is my array:

// $list_of_phones (array)
Array
(
    [0] => Array
        (
            [Manufacturer] => Apple
            [Model] => iPhone 3G 8GB
            [Carrier] => AT&T
        )

    [1] => Array
        (
            [Manufacturer] => Motorola
            [Model] => Droid X2
            [Carrier] => Verizon
        )
)

I’m wanting to be able to do something like the following:

// This is not a real function, just used for example purposes
$phone_id = multi_array_search( array('Manufacturer' => 'Motorola', 'Model' => 'Droid X2'), $list_of_phones );

// $phone_id should return '1', as this is the index of the result.

Any ideas or suggestions on how I can or should 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-16T00:40:54+00:00Added an answer on June 16, 2026 at 12:40 am

    Perhaps this will be useful:

      /**
       * Multi-array search
       *
       * @param array $array
       * @param array $search
       * @return array
       */
      function multi_array_search($array, $search)
      {
    
        // Create the result array
        $result = array();
    
        // Iterate over each array element
        foreach ($array as $key => $value)
        {
    
          // Iterate over each search condition
          foreach ($search as $k => $v)
          {
    
            // If the array element does not meet the search condition then continue to the next element
            if (!isset($value[$k]) || $value[$k] != $v)
            {
              continue 2;
            }
    
          }
    
          // Add the array element's key to the result array
          $result[] = $key;
    
        }
    
        // Return the result array
        return $result;
    
      }
    
      // Output the result
      print_r(multi_array_search($list_of_phones, array()));
    
      // Array ( [0] => 0 [1] => 1 )
    
      // Output the result
      print_r(multi_array_search($list_of_phones, array('Manufacturer' => 'Apple')));
    
      // Array ( [0] => 0 )
    
      // Output the result
      print_r(multi_array_search($list_of_phones, array('Manufacturer' => 'Apple', 'Model' => 'iPhone 6')));
    
      // Array ( )
    

    As the output shows, this function will return an array of all keys with elements which meet all the search criteria.

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

Sidebar

Related Questions

I have an array list of objects and I am using this example to
For example I have this array: int a[] = new int[]{3,4,6,2,1}; I need list
I have a listview connected to a custom array adapter. This list shows information
I have a string like this: TEST.DATA.Data.COR.Point,2;TEST.DATA.Data.COR.Point,5;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.WordTOFIND,18 I have a list of array with
I have a array list in which I bind the data This is a
Folks, I have this array: var list = new Array('Archer','Archer','Banker','Lantern','Toryboy','The Barb','Tim Whiffler','Glencoe','Warrior','Nimblefoot','The Pearl','The Quack','Don
I have an array of arrays in PHP in this layout for example, Key1
I have an Array List that I want to output like my example below.
I have numbers in an array list which also contains alphanumeric. For example. 1
I have some problem to compare values from different array list From this values,

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.