php教程|php手册
php,数组,索引关联数据,转换,json对象
php教程-php手册
源码交易哪家好,vscode记录代码量,ubuntu安装口令,怎么查看tomcat配置,编译sqlite3 r树,增量式爬虫只会在需要的时候,php处理xml, 查询,局域网php电影网站源码,html叠层模板lzw
这篇文章主要介绍了php实现数组中索引关联数据转换成json对象的方法,基于Yii框架分析了php数组与json格式数据的转换技巧,需要的朋友可以参考下
p2p .net源码下载,ubuntu怎么指令换行,什么叫书库爬虫,php 参数…,深圳福田seolzw
云盘网盘源码,vscode怎么卸载vim,ubuntu 网卡性能,tomcat启动后地址,爬虫可以,php7 支持mysql,河源seo优化怎么收费,简洁的html网站源码,招聘模板网页源代码lzw
本文实例讲述了php实现数组中索引关联数据转换成json对象的方法。分享给大家供大家参考。具体实现方法如下:
public static function encode(&$var)
{
return ‘{‘.implode(‘,’,self::encodeExcute($var)).’}’;
}
private static function encodeExcute(&$var)
{
$json = array();
switch (gettype($var))
{
case ‘array’:
foreach($var as $key=>$value)
{
if(is_array($value))
{
$json[] = ‘”‘.$key.”:{‘.implode(‘,’,self::encodeExcute($value)).’}’;
//$json[$key] = self::encode($value);
} elseif (is_object($value)) {
$json[] = “\\”{$key}\\”:”.json_encode($value->attributes);
} else {
echo ‘ERROR 未知类型,还未解析’;
Yii::app()->end();
}
}
break;
case ‘object’:
break;
}
return $json;
}
,