数码资讯
javascrip实现PHPprint_r函数的数量(三种方法)
方法1 复制代码代码如下所示: 功能print_r(theobj){ 无功retstr =; 如果(typeof theobj = = 'object){ retstr + =; 对于(VAR P theobj){ 如果(typeof theobj { p } = = 'object){ retst
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
方法1
复制代码代码如下所示:
功能print_r(theobj){
无功retstr =;
如果(typeof theobj = = 'object){
retstr + =;
对于(VAR P theobj){
如果(typeof theobj { p } = = 'object){
retstr ={+ P + } = > +类型+(theobj);
retstr + = + +(P print_r theobj { });
{人}
retstr ={+ P + P + theobj } { } += >;
}
}
retstr + =;
}
返回retstr;
}
方法二
复制代码代码如下所示:
$(文档)Ready(函数(){)
$(# BTN)。Click(function(){)
jsonstr = $(var的# JSONData)。瓦迩();
var json = eval('(' + jsonstr + ')');
(函数(){())
无功print_r =功能(O,深度){
var =;
| |深度(深度= 1);
var =新数组(4 *深度+ 1);
无功indentnext =新的阵列(4×(深度+ 1)+ 1)。加入();
无功indentnexttwo =新的阵列(4×(深度+ 2)+ 1)。加入();
var =;
变量类型=型O;
开关(类型){
case'string:
case'number:
case'boolean:
case'undefined:
case'function:
TMP =缩进+ indentnext + O +;
打破;
case'object:
违约:
对于(var在o中){
TMP = indentnexttwo +{+键+=};
TMP = print_r(O {key}(深度+ 1));
}
}
结果=类型+;
结果:indentnext(+;
结果= TMP;
结果:indentnext ++;
返回结果;
};
警报(print_r(JSON));
}(JSON);
});
});
方法三
复制代码代码如下所示:
print_r:功能(theobj){
无功retstr =;
如果(typeof theobj = 'object| |型theobj = = 'array){
retstr + =;
对于(VAR P theobj){
如果(typeof theobj { } { } theobj 'object'typeof P P | | = = = = 'array){
retstr ={+ P + } = > +类型+(theobj);
retstr + = + +(P xfupload.tools.print_r theobj { });
{人}
retstr ={+ P + P + theobj } { } += >;
}
}
retstr + =;
}
$(体)追加(retstr);
}
复制代码代码如下所示:
功能print_r(theobj){
无功retstr =;
如果(typeof theobj = = 'object){
retstr + =;
对于(VAR P theobj){
如果(typeof theobj { p } = = 'object){
retstr ={+ P + } = > +类型+(theobj);
retstr + = + +(P print_r theobj { });
{人}
retstr ={+ P + P + theobj } { } += >;
}
}
retstr + =;
}
返回retstr;
}
方法二
复制代码代码如下所示:
$(文档)Ready(函数(){)
$(# BTN)。Click(function(){)
jsonstr = $(var的# JSONData)。瓦迩();
var json = eval('(' + jsonstr + ')');
(函数(){())
无功print_r =功能(O,深度){
var =;
| |深度(深度= 1);
var =新数组(4 *深度+ 1);
无功indentnext =新的阵列(4×(深度+ 1)+ 1)。加入();
无功indentnexttwo =新的阵列(4×(深度+ 2)+ 1)。加入();
var =;
变量类型=型O;
开关(类型){
case'string:
case'number:
case'boolean:
case'undefined:
case'function:
TMP =缩进+ indentnext + O +;
打破;
case'object:
违约:
对于(var在o中){
TMP = indentnexttwo +{+键+=};
TMP = print_r(O {key}(深度+ 1));
}
}
结果=类型+;
结果:indentnext(+;
结果= TMP;
结果:indentnext ++;
返回结果;
};
警报(print_r(JSON));
}(JSON);
});
});
方法三
复制代码代码如下所示:
print_r:功能(theobj){
无功retstr =;
如果(typeof theobj = 'object| |型theobj = = 'array){
retstr + =;
对于(VAR P theobj){
如果(typeof theobj { } { } theobj 'object'typeof P P | | = = = = 'array){
retstr ={+ P + } = > +类型+(theobj);
retstr + = + +(P xfupload.tools.print_r theobj { });
{人}
retstr ={+ P + P + theobj } { } += >;
}
}
retstr + =;
}
$(体)追加(retstr);
}
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。