How to get the generated Array from the print_r() function to send in the email?

Asked

Viewed 212 times

2

I’m developing a log system and need to get the data generated by print_r(), to send in the email if any error occurs in the API, this way the developers will be warned, already containing all the data, including the array.

Grateful!

  • 1

    What’s the matter? $log = print_r($objeto, true); this way it is not displayed but stored in $log.

  • Thanks anyway, I didn’t even notice you had this parameter. ;)

1 answer

2


To take the output/structure of some variable with the print_r() inform the second argument as true, thus the function returns the structure of the variable passed instead of printing on the screen.

<?php
   $arr = range(1,5);
   $log = print_r($arr, true);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.