print_r() prints out only 150 elements in array

When I test arrays I use this.

I'm pretty sure this is a default helper function called: dd()

$array;  // That is 200 elements long.

var_dump($array);
die(); // Prevents html from being rendered if executed in the controller or model.

Every time I try to do this in my view it gets messed up by the HTML like Iserni said.


The array is obviously correct, or at least it is 200 elements long.

The problem then is that Laravel probably does not expect you to shoot output using echo or var_dump or print_r, and "directly output'ed HTML" is likely to smash against some kind of output processor unless you leverage Laravel's Logger class.

It might be a coincidence, but your output size seems to fall around 16 Kb, which is the preferred buffer size of several processors/beautifiers/HTML cleaners.

What happens if you array_slice, say, the first 20 elements off the beginning of your array? Do only 130 elements get displayed, or do you still see 150 (more or less) elements?

Edit: if you really have to use echo, print_r or any "non-Laravel" method to output something quick&dirty, you may almost certainly do it like this:

  // Open another output buffering context
  ob_start();

  print_r($WHATEVER);

  $_output = ob_get_contents();
  // Destroy the context so that Laravel's none the wiser
  ob_end_clean();

  $_fp = fopen("/tmp/myfile.txt", "w");
  fwrite($_fp, $_output);
  fclose($_fp);
  // Remove awkward traces
  unset($_fp, $_output);

You may also encapsulate the last part into a function of your own, so that you can write

  // in helpers.php
  function myObStop($file, $mode = 'a') {
      $_output = ob_get_contents();
      // Destroy the context so that Laravel's none the wiser
      ob_end_clean();

      $_fp = fopen($file, $mode);
      fwrite($_fp, $_output);
      fclose($_fp);
  }

  ob_start();
  print "Whatever";
  myObStop('/tmp/myfile.txt', 'w');

and leave Laravel executing after that. But I strongly advise to exploit Logger instead:

  http://laravel.com/docs/logging#logging