"内容1", "内容2" => "内容2", &"/> "内容1", "内容2" => "内容2", &">
Home > Backend Development > PHP Tutorial > php怎么把array的key设置为和value相等

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

WBOY
Release: 2016-06-13 10:26:38
Original
948 people have browsed it

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>
Copy after login
PHP code
$arr = array ( 0 => '内容1', 1 => '内容2' ,2 => '内容3');$r = array_combine(array_values($arr), $arr);print_r($r);<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template