print_r的替代品(仅显示2个3键) [英] alternative of print_r ( to display only upto 2 3 keys)
问题描述
我有一个多维数组
,具有200个键,每个键都有3到5个数组。
I have a multi dimensional array
with 200 keys and each key has 3 to 5 arrays.
I想知道有没有办法只看到一个有限的部分(即最多3或4个键)
,因为如果我使用 print_r($ desiredArray);
那么它花了太多的时间打印完整的阵列,我只想看到初始2或3前两个和最后两个数组键
I want to know is there any way to see only a limited part ( i.e. upto 3 or 4 keys)
because if i use print_r($desiredArray);
then it took too much time to print that complete array and I want to see only initial 2 or 3 either first two and last two array keys
如下所示
$ desiredArray [0] $ desiredArray [1] ... $ desiredArray [199] $ desiredArray [200]
..
如果键不顺序,则显示如下
if key are not in order then display like below
current($desiredArray), next($desiredArray)...end($desiredArray)
推荐答案
一个可能的解决方案是安装 XDebug 扩展程序。使用XDebug安装,像 var_dump()
这样的功能会产生很好的彩色输出,防止递归,深嵌套或过长的输出。
One possible solution is installing the XDebug extension. With XDebug installed, functions like var_dump()
produce nicely coloured output with protection against recursion, deep nesting or overly long output.
快速修复DIY替代方案是:
The quick-fix DIY alternative would be:
print_r(array_slice($desiredArray, 0, 4));
这篇关于print_r的替代品(仅显示2个3键)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!