3

I have a multi dimensional array with 200 keys and each key has 3 to 5 arrays.

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

just like below

$desiredArray[0] $desiredArray[1] ... $desiredArray[199 ] $desiredArray[200]..

if key are not in order then display like below

current($desiredArray), next($desiredArray)...end($desiredArray)
Rich
  • 5,603
  • 9
  • 39
  • 61
xkeshav
  • 53,360
  • 44
  • 177
  • 245
  • Write your own function, using `current()`, `next()`, `prev()` and `end()` standard functions. – biakaveron Mar 24 '11 at 08:07
  • Possible duplicate of [Using print\_r and var\_dump with circular reference](http://stackoverflow.com/questions/6292164/using-print-r-and-var-dump-with-circular-reference) – kenorb Apr 08 '16 at 00:11

4 Answers4

8

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.

The quick-fix DIY alternative would be:

print_r(array_slice($desiredArray, 0, 4));
Michiel Pater
  • 22,377
  • 5
  • 43
  • 57
Sander Marechal
  • 22,978
  • 13
  • 65
  • 96
3

There are many extended versions of print_r.

and couple others. I am sure you'll find one will suit you.

However I'd like Sander's proposal for it's being very smart.

raveren
  • 17,799
  • 12
  • 70
  • 83
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
1

The TVarDumper class is also very good.

kenorb
  • 155,785
  • 88
  • 678
  • 743
0

You'll need to roll your own. print_r is simply a dump command to help in debugging. If you wrote a function for yourself that got the count of each sub array and only dumped out the last couple. You could make it configurable also.

Publish it on GitHub as it may be of interest to others.

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
  • Thank for your valuable suggsetion, but i dont know how to publish on GitHub as my description is also not formatted.. – xkeshav Mar 24 '11 at 08:09