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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:18:29+00:00 2026-06-07T13:18:29+00:00

I have two associative arrays: ArrayA = array( [10] => ten [12] => twelve

  • 0

I have two associative arrays:

ArrayA = array( [10] => ten
                [12] => twelve
                [22] => 10
                [30] => 10, 12, 8
         )
ArrayB = array( [10] => net
                [12] => evlewt
                [22] => 11, 12, 10
                [30] => 10
         )

The values of same keys on both arrays need to be compared. Some keys have CSV values and that can be on both the arrays.

For instance, [22] on ArrayA should be checked in CSV on ArrayB. Likewise, [30] in ArrayB should be checked in CSV on ArrayA. Others should be compared as usual ==

Note: I am trying to avoid a looping here. We can certainly do this in multiple ways with Loop. I am wondering if there is a quick and efficient way to do this without looping.

Edit: To clarify further, this is how these two should be compared:

Is "ten" in ArrayA == "net" in ArrayB?
Is "twelve" in ArrayA == "evlewt" in ArrayB?
Is 10 in ArrayA existing in (11, 12, 10) of ArrayB?
Is (10, 12, 8) of ArrayA containing the 10 ArrayB?
  • 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-07T13:18:31+00:00Added an answer on June 7, 2026 at 1:18 pm

    I hope I understand the question correctly. If you normalize the data first you can just compare the arrays

    For instance:

    $a = array(
        10 => 'net',
        12 => 'evlewt',
        22 => '10,12,11',
        30 => '12,10'
    );
    
    $b = array(
        10 => 'net',
        12 => 'evlewt',
        22 => '11,12,10',
        30 => '12,10'
    );
    
    function normalize(&$value, $key) {
        $value = explode(',', $value);
        sort($value);
        $value = implode(',', $value);
    }
    
    array_walk($a, 'normalize');
    array_walk($b, 'normalize');
    
    var_dump($a == $b); // outputs true
    

    EDIT: In order to evaluate two arrays by whether an element in either array is a subset of another, I would normalize values to array and use the reduce_array() function.

    <?php
    $a = array(
        10 => 'net',
        12 => 'evlew',
        22 => '10,12,11',
        30 => '12,10,11'
    );
    
    $b = array(
        10 => 'net',
        12 => 'evlewt',
        22 => '11,12,10',
        30 => '12,10'
    );
    
    function normalize(&$value, $key) {
        $value = explode(',', $value);
    }
    
    function compare_value($v, $w) {
        if (false === $v) return false;
        global $a, $b;
        if(is_subset($a[$w], $b[$w]) || is_subset($b[$w], $a[$w]))
            return true;
        return false;
    }
    
    function is_subset($needle, $haystack) {
         return count(array_intersect($needle, $haystack)) === count($needle);
    }
    
    array_walk($a, 'normalize');
    array_walk($b, 'normalize');
    
    $result = array_reduce(array_keys($a), 'compare_value', true);
    var_dump($result); // outputs false
    
    $a = array(
        10 => 'net',
        12 => 'evlewt',
        22 => '10',
        30 => '12,10,11'
    );
    
    $b = array(
        10 => 'net',
        12 => 'evlewt',
        22 => '11,12,10',
        30 => '12,10'
    );
    
    array_walk($a, 'normalize');
    array_walk($b, 'normalize');
    
    $result = array_reduce(array_keys($a), 'compare_value', true);
    var_dump($result); // outputs true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two sequential (non-associative) arrays whose values I want to combine into a
I like to learn how to combine two associative array which has same keys
I have two arrays. ArrayA is numeric (ArrayA => 3, 7, 8) ArrayB is
I have two arrays, both associative; ArrayUneaten ( lemon=> 7, banana=>6, apple=>10)//the units of
i have these two associative arrays // the needle array $a = array( who
If I have two associative arrays, what would be the most efficient way of
I have two associative arrays in PHP that are defined as following: $this_week[] =
I have a problem concatenating two associative arrays in JavaScript. Below is the sample
I have an associative array with two object inside. Running this through $(myassoc).each() ,
I have a question about associative arrays in php. I have following array in

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.