Home  >  Article  >  Backend Development  >  php 轮换 已有数组键值

php 轮换 已有数组键值

WBOY
WBOYOriginal
2016-06-13 11:15:291106browse

php 替换 已有数组键值

本帖最后由 html5cloud 于 2013-02-25 13:57:00 编辑
<br />	      foreach($arry1 as $key => $value) {<br /> if (array_key_exists($key,$arry2))<br />	{<br />	  $arry2[$key]=$value;<br />	}<br /> else<br />	{<br />	  array_push($arry2,"$key=>$value");<br />	  ksort($arry2);<br />	}<br /> 	        }<br />


需求: 如果数组arry2中有arry1中的属性,则arry2中该属性值替换为arry1该属性值;如果没有则加入进入.
数组是 key=> value 那样的,如arry[a:1,b:[1,2]] 
上面代码为何有问题呢?

------解决方案--------------------
array_push($arry2,"$key=>$value");
改为
$arry2[$key] = $value");
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