1,"3123123"=>1,"221112"=0); 怎么转成json类数组格式啊,如下:谢谢PHP code $output = [msg,{"tel":"13"/> 1,"3123123"=>1,"221112"=0); 怎么转成json类数组格式啊,如下:谢谢PHP code $output = [msg,{"tel":"13">

首页 >后端开发 >php教程 > 数组转换,该如何处理

数组转换,该如何处理

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原创
2016-06-13 13:28:03802浏览

数组转换
有一数组:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->$input = array("13546465"=>1,"3123123"=>1,"221112"=0);


怎么转成json类数组格式啊,如下:谢谢

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->$output = [msg,{"tel":"13546465","status":"1"},{"tel":"3123123","status":"1"},{"tel":"221112","status":"0"}]


------解决方案--------------------
PHP code
$input = array("13546465"=>1,"3123123"=>1,"221112"=>0);
$r[] = 'msg';
foreach($input as $k=>$v)
  $r[] = array('tel' => "$k", 'status' => "$v");

$output = json_encode($r);

echo $output; <div class="clear">
                 
              
              
        
            </div>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn