Convert array of keys to associative array

user391986

I have an array of data like so

[
 'one', 'two', 'three'
]

I need to convert it like so

[
  'one' => 'one',
  'two' => 'two'
]

I found out about array_flip which gives me

[
   'one' => 0,
   'two' => 0,
   'three' => 0
]

What can I do from there? Any clean PHP way to do this?

mike.k

array_combine() is the way to go

$a = array('one', 'two', 'three');
$output = array_combine($a, $a);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to convert a PHP array to an associative array, using index as keys?

From Dev

Filter associative array with keys array

From Dev

Modify array keys of an associative array

From Dev

Convert JSON to Associative array

From Dev

Convert JSON to Associative array

From Dev

Convert strings to associative array

From Dev

How to convert array to associative array?

From Dev

convert an index array to an associative array

From Dev

Split associative array based on keys

From Dev

Associative array with similar keys assignment

From Dev

Split associative array based on keys

From Dev

BASH associative array rearrange keys

From Dev

How to get keys of an associative array as an array

From Dev

Create an associative array using another array as keys

From Dev

Offset printing array keys in an associative object array

From Java

Convert a PHP object to an associative array

From Dev

Convert Associative Array -> Grouping by Value

From Dev

Convert JSON Object array into associative array

From Dev

How to convert a associative array into a sorted string array?

From Dev

Convert Associative array to different array structure

From Dev

Convert index array in associative array php for loop

From Dev

Method to convert an associative array into an indexed array

From Dev

how to convert index array to associative array?

From Dev

Convert index array in associative array php for loop

From Dev

php - how to convert an associative array to a multidimensional array

From Dev

How to convert numerically indexed array to associative array

From Dev

How to convert Doctrine array to PHP associative array

From Dev

Php, how to swap two associative array KEYs?

From Dev

how to use strings as associative array keys?

Related Related

  1. 1

    How to convert a PHP array to an associative array, using index as keys?

  2. 2

    Filter associative array with keys array

  3. 3

    Modify array keys of an associative array

  4. 4

    Convert JSON to Associative array

  5. 5

    Convert JSON to Associative array

  6. 6

    Convert strings to associative array

  7. 7

    How to convert array to associative array?

  8. 8

    convert an index array to an associative array

  9. 9

    Split associative array based on keys

  10. 10

    Associative array with similar keys assignment

  11. 11

    Split associative array based on keys

  12. 12

    BASH associative array rearrange keys

  13. 13

    How to get keys of an associative array as an array

  14. 14

    Create an associative array using another array as keys

  15. 15

    Offset printing array keys in an associative object array

  16. 16

    Convert a PHP object to an associative array

  17. 17

    Convert Associative Array -> Grouping by Value

  18. 18

    Convert JSON Object array into associative array

  19. 19

    How to convert a associative array into a sorted string array?

  20. 20

    Convert Associative array to different array structure

  21. 21

    Convert index array in associative array php for loop

  22. 22

    Method to convert an associative array into an indexed array

  23. 23

    how to convert index array to associative array?

  24. 24

    Convert index array in associative array php for loop

  25. 25

    php - how to convert an associative array to a multidimensional array

  26. 26

    How to convert numerically indexed array to associative array

  27. 27

    How to convert Doctrine array to PHP associative array

  28. 28

    Php, how to swap two associative array KEYs?

  29. 29

    how to use strings as associative array keys?

HotTag

Archive