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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:18:01+00:00 2026-06-02T07:18:01+00:00

i have these two associative arrays // the needle array $a = array( who

  • 0

i have these two associative arrays

// the needle array

$a = array(
"who" => "you", 
"what" => "thing", 
"where" => "place",
"when" => "hour"
);

// the haystack array

$b = array(
"when" => "time", 
"where" => "place", 
"who" => "you",
"what" => "thing"
);

i want to check if the $a has a match with the b with it’s exact key and value

and if each key and value from $a has an exact match in $b…. i want to increment the value of a variable $c by 1 and so on…

as we’ve seen from above there 3 possible match…
and supposedly results to increment the value of $c by 3

$c = "3";

i hope some genius can help me…

  • 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-02T07:18:02+00:00Added an answer on June 2, 2026 at 7:18 am

    EDIT2

    OP actually used array_intersect_assoc() for their specific usecase. (check comment)

    The original answer was not really useful for their case!


    you can look into the php’s array_diff_assoc() function or the array_intersect() function.

    EDIT

    Here’s a sample on counting the matched values:

    <?php
      $a = array(
        "who" => "you", 
        "what" => "thing", 
        "where" => "place",
        "when" => "hour"
      );
      // the haystack array
      $b = array(
        "when" => "time", 
        "where" => "place", 
        "who" => "you",
        "what" => "thing"
      );
      $c = count(array_intersect($a, $b));
      echo $c;
    ?>
    

    CODEPAD link.

    • 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 have two Collection objects, I want to associate each object of these two
I have these two URL's I want to make available to my users: /Account/Orders
I have two associative arrays in PHP that are defined as following: $this_week[] =
I have two arrays, one is a node-node-cost array [a_node,b_node,cost] which has 8000 entries
I have a question about associative arrays in php. I have following array in
Say I have a very large dictionary / associative array and I want to
I have two large arrays: $a = array('a1','a2','a3','a4'); // and so on $b =
I have these two modules : package G1; sub new { my $class =
I have these two classes public class Person { } public class Company {

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.