删除字符串"Array",从print_r()的输出 [英] Remove string "Array" from print_r()'s output
本文介绍了删除字符串"Array",从print_r()的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从 print_r()
中删除打印输出中的字符串"Array"?我尝试使用字符串替换,但是没有用.
How can I remove the string "Array" in the printout from print_r()
?
I have tried using string replace, but it didn't work.
示例输出:
Array (
[0] => Array (
[id] => Classify318721363801824
[classification] =>
Array (
[0] => Array (
[Klasifikasi] => NonOpini
[Nilai] => 0.999946 )
[1] => Array (
[Klasifikasi] => Opini
[Nilai] => 5.43418e-005 ) )
推荐答案
在 TRUE
上为 print_r()设置
函数以字符串形式返回数组打印,而不是使用str_replace替换任何内容.返回标志
(secont func arg)
Set return flag
(secont func arg) at TRUE
for print_r()
function to return array print as string, than replace whatever you want using str_replace.
echo str_replace('Array','',print_r($arr,true));
我想您也想替换不需要的新行.这是我自己的函数,可以很好地打印数组.
I suppose you also want to replace unneeded new lines. Here's my own func to print arrays nicely.
function aprint($arr, $return = false) {
$wrap = '<div style=" white-space:pre; position:absolute; top:10px; left:10px; height:200px; width:100px; overflow:auto; z-index:5000;">';
$wrap = '<pre>';
$txt = preg_replace('/(\[.+\])\s+=>\s+Array\s+\(/msiU','$1 => Array (', print_r($arr,true));
if ($return) return $wrap.$txt.'</pre>';
else echo $wrap.$txt.'</pre>';
}
这篇关于删除字符串"Array",从print_r()的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文