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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:23:06+00:00 2026-06-05T06:23:06+00:00

There is function array_values in PHP such that $array2 = array_values($array1); $array2 has the

  • 0

There is function array_values in PHP such that

$array2 = array_values($array1);

$array2 has the same values as $array1 but keys are from
0 to sizeof($array1) - 1. Is it possible to get mapping from old keys to new keys?

EDIT. I will explain on an example:

$array1 = array( 'a' => 'val1', 'b' => 'val1');
$array2 = array_values( $array1 );

so now array2 has next values

$array2[0] = 'val1'
$array2[1] = 'val2'

How get array3 such that:

$array3['a'] = 0
$array3['b'] = 1
  • 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-05T06:23:07+00:00Added an answer on June 5, 2026 at 6:23 am

    To produce a key map you need to first get the keys into a regular array and then flip the keys and values:

    $array1_keymap = array_flip(array_keys($array1));
    

    For example:

    $array1 = array(
        'a' => 123,
        'b' => 567,
    );
    
    $array1_values = array_values($array1);
    $array1_keymap = array_flip(array_keys($array1));
    

    Value of $array1_values:

    array(
        0 => 123,
        1 => 567,
    );
    

    Value of $array1_keymap:

    array(
        'a' => 0,
        'b' => 1,
    );
    

    So:

    $array1['a'] == $array1_values[$array1_keymap['a']];
    $array1['b'] == $array1_values[$array1_keymap['b']];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm interested if there is any function like array_map or array_walk from php. Don't
I come from a php background and in php, there is an array_size() function
In php is there a function to increment the values of subsequent values twice(*2)
Maybe I'm going insane, but I could have sworn that there was an PHP
Is there any PHP function that can be used in my case ? Currently
Is there an already existing function in PHP for creating an associative array from
I am creating a PHP function that will take some values, one of which
In the php documentation listed here there's an indication that the function uses the
Is there any function available in PHP to check whether an array is empty
is there a similar function in python that takes search(array) and replace(array) as a

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.