Home >Backend Development >PHP Tutorial >怎么把数组键名键值重置

怎么把数组键名键值重置

WBOY
WBOYOriginal
2016-06-23 13:05:063918browse

array(6) {
  [0] => string(6) "品牌"
  [1] => string(6) "ABC"
  [2] => string(6) "颜色"
  [3] => string(20) "黄色|红色|黄色"
  [4] => string(6) "型号"
  [5] => string(18) "20FGH-111"
}

结果:

array(3) {
  ["品牌"] => string(6) "ABC"
  ["颜色"] => string(20) "黄色|红色|黄色"
  ["型号"] => string(18) "20FGH-111"
}

完全没有头绪啊,谢谢。


回复讨论(解决方案)

for($i=0; $i<count($原数组); $i+=2) {  $新数组[$原数组[$i]] = $原数组[$i+1];}

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