$items = "word1 word2 word3 word4";
$items = explode(" ", $items);
$ items是我的数组,我怎么能把它变成这个
我怎样才能让word1成为一把钥匙和一个价值?
"word1" => "word1"
答案 0 :(得分:8)
$newArray =
array_combine
($items, $items);
答案 1 :(得分:1)
foreach($items as $item) {
$newArr[$item] = $item;
}
答案 2 :(得分:1)
$items = "word1 word2 word3 word4";
$temp = explode(" ", $items);
$result = array();
foreach ($temp as $value) {
$result[$value] = $value;
}