How does php set the key of array to be equal to value? the following Array array ([0] & gt; content 1 [1] & gt; content 2 [2] & gt; content 3) the following Array (& quot; content 1 & quot; & gt; & quot; content 1 & quot;, & quot; content 2 & quot; & gt; & quot; content 2 & quot;, & php how to set the array key to be equal to the value
The following array is available:
Array ([0] => Content 1 [1] => content 2 [2] => Content 3)
The following array is expected to be produced after processing
Array ("content 1" => "content 1", "content 2" => "content 2", "Content 3" => "content 3 ")
------ Solution --------------------
Foreach traverses the array and then uses the for loop to loop with the key value.
------ Solution --------------------
PHP code
$ Arr = array (0 => 'Content 1', 1 => 'Content 2', 2 => 'Content 3'); foreach ($ arr as $ v) $ k [] = $ v; print_r (array_combine ($ k, $ arr ));
------ Solution --------------------
PHP code
$ Arr = array (0 => 'Content 1', 1 => 'Content 2', 2 => 'Content 3 '); $ r = array_combine (array_values ($ arr), $ arr); print_r ($ r );