Skip to content
Advertisement

print_r() for many objects

For logging purposes, I am looking for something that behaves like print_r() (or similar), but accepts not only one object to be displayed, but many of them. Such as var_dump() is doing.

Desired:

$text = "Error " . print_r($obj1, $obj2, $obj3...);  // print_r many objects in one call
log_message('info', $text);

Any suggestions?

Advertisement

Answer

Since no one is doing it… Self-answered question, based on @Peter Krebs comment:

Nesting the many objects within [ ] for converting it to a single array can just do the job:

$text = "Error " . print_r([$obj1, $obj2, $obj3]);  // print_r many objects in one call
log_message('info', $text);

Simple, smart.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement