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

数组转换,该如何处理

WBOY
Release: 2016-06-13 13:28:03
Original
733 people have browsed it

数组转换
有一数组:

PHP code
<!--

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

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


怎么转成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"}]
Copy after login


------解决方案--------------------
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>
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!