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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:09:04+00:00 2026-05-27T16:09:04+00:00

$array1 = array( [0] => 2 [1] => 3 [2] => 5 [3] =>

  • 0
$array1 = array( [0] => 2 [1] => 3 [2] => 5 [3] => 6 [4] => 7 [5] => 8 [6] => 9 ) ;

$array2 = array( ( [0] => Array (...) [1] => Array (...) [2] => Array (...) ... [6] => Array (...));

They have the same number of elements. I want the array2 to have, as keys, the values of array1.

Should become:

 $array2 = array( ( [2] => Array (...) [3] => Array (...) [5] => Array (...) ... [9] => Array (...));

I have written this code but, I dunno why it returns only a part of array2.

reset($array1);reset($array2);
foreach ($array2 as $k => $v) {
   unset ($array2[$k]);

   $new_key =  current($array1);
   next($array1);
   $array2[$new_key] = $v;
}
print_r($array2);

Thanks in advance.

  • 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-27T16:09:05+00:00Added an answer on May 27, 2026 at 4:09 pm

    Use array_combine to create an object with keys from one array, and the values from another.

    $array_1 = array ('hello','world','stackoverflow');
    $array_2 = array (
      array ('greetings'),
      array ('planet'),
      array ('websitefilledwithgeeks')
    );
    
    print_r (
      array_combine ($array_1, $array_2)
    );
    

    output

        Array
    (
        [hello] => Array
            (
                [0] => greetings
            )
    
        [world] => Array
            (
                [0] => planet
            )
    
        [stackoverflow] => Array
            (
                [0] => websitefilledwithgeeks
            )
    
    )
    

    Documentation of PHP: array_combine

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

Sidebar

Related Questions

I have a number of objects collected in an array. The same objects are
Ruby on Rails controllers will automatically convert parameters to an array if they have
I have a bidimensional Object array in Java. Some indices aren´t used, because they
I have two JavaScript arrays: var array1 = [Vijendra,Singh]; var array2 = [Singh, Shakya];
I have an array of y-values that form a line. Additionally, I have an
Sitation: overview: I have something like this: std::vector<SomeType> values; std::vector<int> indexes; struct Range{ int
I want to iterate over two arrays at the same time, as the values
I have 2 one dimensional arrays, containing the exact same values: public int[] start
I have a multi-dimensional array similar to the example below that I want to
I have two arrays containing the same elements, but in different orders, and I

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.