简体   繁体   中英

How to build this php array?

$items  = "word1 word2 word3 word4";
$items = explode(" ", $items);

$items is my array, how can I have it turn into this

Like how can I make word1 be a key and a value?

"word1" => "word1"

$newArray = array_combine ($items, $items);

foreach($items as $item) {
$newArr[$item] = $item;
}
$items  = "word1 word2 word3 word4";
$temp = explode(" ", $items);
$result = array();
foreach ($temp as $value) {
  $result[$value] = $value; 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM