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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:24:20+00:00 2026-05-22T20:24:20+00:00

What is the fastest way to convert a simple array to an associative array

  • 0

What is the fastest way to convert a simple array to an associative array in PHP so that values can be checked in the isset($array[$value])?

I.e. fastest way to do the following conversion:

$array = array(1, 2, 3, 4, 5);
$assoc = array();

foreach ($array as $i => $value) {
        $assoc[$value] = 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-05-22T20:24:21+00:00Added an answer on May 22, 2026 at 8:24 pm

    array_flip() is exactly doing that:

    array_flip() returns an array in flip order, i.e. keys from trans become values and values from trans become keys.

    Note that the values of trans need to be valid keys, i.e. they need to be either integer or string. A warning will be emitted if a value has the wrong type, and the key/value pair in question will not be flipped.

    If a value has several occurrences, the latest key will be used as its values, and all others will be lost.


    But apart from that, there is only one type of array in PHP. Even numerical ("simple", as you call it) arrays are associative.

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

Sidebar

Related Questions

Using PHP, what's the fastest way to convert a string like this: 123 to
Can anyone tell me what is the fastest way to programmatically convert a SAS
What is the fastest way you know to convert a floating-point number to an
I'm looking for the fastest way to obtain the value of π, as a
What's the fastest way using either DOS scripting or PowerShell to run this simple
I need fastest way to convert files from latin1 to utf-8 in python. The
In a recent question I asked about the fastest way to convert a large
This is a Java question. What is the fastest way to convert a List<?>
What is the fastest way to sum up an array in JavaScript? A quick
What is the fastest way of transferring few thousand rows of data from one

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.