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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:44:36+00:00 2026-06-01T15:44:36+00:00

I have two arrays: $array1 = array(1=>1,10=>1,12=>0,13=>13); $array2 = array(1=>Hello,10=>Test,12=>check,13=>error); Here $array1 has keys

  • 0

I have two arrays:

$array1 = array(1=>1,10=>1,12=>0,13=>13);
$array2 = array(1=>"Hello",10=>"Test",12=>"check",13=>"error");

Here $array1 has keys and values. Now I want to take the first value from $array1(as 1) and I want to check if this is repeated in this array .

Here 1 is repeated two times so I want to take the two keys 1,10 and display the corresponding values of these keys from $array2. If the value in $array1 is not repeated then I want to just display the value of this key from $array2.

I want to get the output as follows:

Hello Test
check
error

That means in $array1 1,10 keys have the same value so the value of 1 and the value of 10 from $array2 is merged then displayed.

Like 12 has 0 this is not repeated so simply take value of 12 from $array2.

Like 13.

How can I 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-01T15:44:37+00:00Added an answer on June 1, 2026 at 3:44 pm

    This is really rough, but a simple way of doing it could be:

    <?
    
    $array1 = array(1=>1,10=>1,12=>0,13=>13);
    $array2 = array(1=>"Hello",10=>"Test",12=>"check",13=>"error");
    
    $prev = $array1[1];
    
    foreach($array1 as $key => $val)
    {
        if($val != $prev && $key != 1)
        {
            echo '<br />';
        }
    
        echo $array2[$key].' ';
    
        $prev = $val;
    }
    
    ?>
    

    Example: http://codepad.org/OpLdtStp

    This assumes that you’re first key is always going to be 1 by the way.

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

Sidebar

Related Questions

I have two arrays the first one has this structure Parameter Keys array array
Assume that I have two arrays as follow: $array1 = array(1, 3, 5); $array2
I have two JavaScript arrays: var array1 = [Vijendra,Singh]; var array2 = [Singh, Shakya];
Using Javascript, I have two arrays called array1 and array2. I set currentArrray to
How can I Compare values of two arrays to check if 1 array does
Let's say I have two arrays: int[] array1 = new int[2000000]; int[] array2 =
Let's say I have these two arrays: string[] arr1 = new string[2]{Hello, Stack} string[]
i have two arrays like this first array Array ( [0228] => Array (
Suppose I have two arrays like the following: $arr2 = array(array(first, second), array(third, fourth));
Consider I have two arrays: $friends = Array('foo', 'bar', 'alpha'); $attendees = Array('foo', 'bar');

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.