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

The Archive Base Latest Questions

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

Given 2 associative arrays: $fruits = array ( d => lemon, a => orange,

  • 0

Given 2 associative arrays:

$fruits  = array ( "d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple" );
$fruits2 = array ( "e" => "lemon", "f" => "apple",  "g" => "melon",  "h" => "apple" );

I would like to do something like:

for ( $n = count($fruits), $i = 0; $i < $n; $i++)
{
  $test = (bool) $fruits[$i] == $fruits2[$i];
}

This can not work as I am using associative array. What would be the best way to go to achieve that? (This loops is going to be ran intensity so I would like to keep it as light as possible)

EDIT to give more detail on what I am trying to do:

Here is a better example of what I am trying to achieve:

$array   = array ( 1,2,3,4,3,2 );
$array2  = array ( 9,6,3,4,3,2 );
$counts  = array_count_values( $words );
$counts2 = array_count_values( $words2 );

Given the arrays above I need to calculate which array as the highest duplicate integers. Imagine a poker game, comparing two hands that each contain duplicate cards, how to evaluate which set of duplicate (whether double, triple or quadruple ) as the highest value.

  • 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-27T07:57:49+00:00Added an answer on May 27, 2026 at 7:57 am

    Got it working this way :

    $n = count($fruits);
    for ( $i = 0; $i < $n; $i++)
    {
      $cur_vals_1 = each ($fruits);
      $cur_vals_2 = each ($fruits2);
    
      $sum1 += $cur_vals_1['key'] * $cur_vals_1['value'];
    
      ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given an associative array: array(key1 => value1, key2 => value2, ...) How would I
Given an associative array (of the sort returned by jQuery.serializeArray() ) like this: [
Given a PHP associative array like this one: $a = array( 'color' => 'red',
Given an absolute or relative path (in a Unix-like system), I would like to
Given the following two indexed arrays: $a = array('a', 'b', 'c'); $b = array('red',
i have the following associative array word => count where word is an english
Is there a way to copy an associative array? I realize that regular arrays
I've been given an array that needs to be sorted by its key (associative
Given a specific DateTime value, how do I display relative time, like: 2 hours
Given 2 rgb colors and a rectangular area, I'd like to generate a basic

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.