• support@answerspoint.com

cakephp log an array as var_dump

3956

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.

2Answer


0

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 8 years ago
  • Gul Hafiz

0

Try:

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 8 years ago
  • Gul Hafiz

Your Answer

    Facebook Share        
       
  • asked 9 years ago
  • viewed 3956 times
  • active 9 years ago

Best Rated Questions