• support@answerspoint.com

cakephp log an array as var_dump


I need to jump into a server side code. It is used cakephp there. I would like to see a variable, I think it is a model, but I am not sure, let be a variable in or case.

CakeLog::write('debug', 'myArray'.var_export($myArray) );

it will have the output

myArray: Array

I would like to see similar output as var_dump can produce to the output.

Is that possible? if yes, than how?

Any help apreciated.



Just use print_r, it accepts a second argument not to output the result.

CakeLog::write('debug', 'myArray'.print_r($myArray, true) );

And if you don't want new lines, tabs or double spaces in your log files:

$log = print_r($myArray, true);
$log = str_replace(array("\n","\t"), " ", $log);
$log = preg_replace('/\s+/', ' ',$log);
CakeLog::write('debug', 'myArray' . $log);
  • answered 7 years ago
  • Gul Hafiz



CakeLog::write('debug', 'myArray'.print_r($myArray, true));

The true parameter makes print_r return the value rather than print on screen, so you can save it.

  • answered 7 years ago
  • Gul Hafiz

Your Answer

    Facebook Share        
  • asked 8 years ago
  • viewed 3664 times
  • active 8 years ago

Best Rated Questions