Search code examples
phparraysassociative-array

How to make all array keys the same as their respective value?


$items  = "word1 word2 word3 word4";
$items = explode(" ", $items);

$items is my array, how can I have it turn into this

Like how can I make word1 be a key and a value?

"word1" => "word1"

Solution

  • $newArray = array_combine($items, $items);