数组将值复制到 PHP 中的键 [英] Array copy values to keys in PHP
本文介绍了数组将值复制到 PHP 中的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个数组:
$a = array('b', 'c', 'd');
有没有简单的方法可以把数组转换成下面这样?
Is there a simple method to convert the array to the following?
$a = array('b' => 'b', 'c' => 'c', 'd' => 'd');
推荐答案
$final_array = array_combine($a, $a);
参考:http://php.net/array-combine
P.S. 小心包含重复键的源数组,如下所示:
P.S. Be careful with source array containing duplicated keys like the following:
$a = ['one','two','one'];
注意重复的 one
元素.
这篇关于数组将值复制到 PHP 中的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文