"内容1", "内容2" => "内容2", &"/> "内容1", "内容2" => "内容2", &">

Home >Backend Development >PHP Tutorial >php怎么把array的key设置为和value相等

php怎么把array的key设置为和value相等

WBOY
WBOYOriginal
2016-06-13 10:26:38945browse

php如何把array的key设置为和value相等
有如下数组
Array ( [0] => 内容1 [1] => 内容2 [2] => 内容3)

希望处理后生产如下数组

Array ("内容1" => "内容1", "内容2" => "内容2", "内容3" => "内容3")

------解决方案--------------------
foreach遍历数组,让后再用for循环以key的值循环。
------解决方案--------------------

PHP code
$arr=array ( 0 => '内容1', 1 => '内容2' ,2 => '内容3');foreach($arr as $v) $k[]=$v;print_r(array_combine($k,$arr));<br><font color="#e78608">------解决方案--------------------</font><br>
PHP code
$arr = array ( 0 => '内容1', 1 => '内容2' ,2 => '内容3');$r = array_combine(array_values($arr), $arr);print_r($r);<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn