Home > Backend Development > PHP Tutorial > 怎么合并2个JSON数组

怎么合并2个JSON数组

WBOY
Release: 2016-06-13 10:56:56
Original
1363 people have browsed it

如何合并2个JSON数组

C# code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$json1 = 
Copy after login


如何合并2个JSON数组?(没有decode的情况下)
array_merge 对JSON无效。有没有什么简易的函数,或者FUNCTION?



------解决方案--------------------
PHP code
$arr1 = array();$arr2 = array();$arr3 = array();$web=json_decode($json1);$arr1=json_to_array($web);$web=json_decode($json2);$arr2=json_to_array($web);$arr3 = array_merge($arr1,$arr2);echo "<pre class="brush:php;toolbar:false">";print_r($arr3);function json_to_array($web){$arr=array();foreach($web as $k=>$w){if(is_object($w)) $arr[$k]=json_to_array($w); else $arr[$k]=$w;}return $arr;}<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template