Home » Php » php – Not var_dump() nor print_r() will show readable information…. but the same confusing output. Why?

php – Not var_dump() nor print_r() will show readable information…. but the same confusing output. Why?

Posted by: admin July 12, 2020 Leave a comment

Questions:

I have some comments inside a drupal node, and tried

var_dump()

and

print_r()

to see the difference between them.
I want to see what´s inside $content variable of $comment object.

I´ve tried both and what I get is the same output!

array(5) { ["#printed"]=> bool(true) ["comment_body"]=> array(18) { ["#theme"]=> string(5) "field" ["#weight"]=> int(0) ["#title"]=> string(10) "Comentario" ["#access"]=> bool(true) ["#label_display"]=> string(6) "hidden" ["#view_mode"]=> string(4) "full" ["#language"]=> string(3) "und" ["#field_name"]=> string(12) "comment_body" ["#field_type"]=> string(9) "text_long" ["#field_translatable"]=> string(1) "0" ["#entity_type"]=> string(7) "comment" ["#bundle"]=> string(21) "comment_node_noticias" ["#object"]=> object(stdClass)#105 (25) { ["cid"]=> string(5) "37616" ["pid"]=> string(1) "0" ["nid"]=> string(4) "4355" ["uid"]=> string(4) "1411" ["subject"]=> string(30) "Esperemos que así sea, ya que" ["hostname"]=> string(15) "190.246.225.229" ["created"]=> string(10) "1307259450" ["changed"]=> string(10) "1307259450" ["status"]=> string(1) "1" ["thread"]=> string(3) "01/" ["name"]=> string(11) "dominguezpm" ["mail"]=> string(0) "" ["homepage"]=> string(0) "" ["language"]=> string(0) "" ["node_type"]=> string(21) "comment_node_noticias" ["registered_name"]=> string(11) "dominguezpm" ["u_uid"]=> string(4) "1411" ["signature"]=> string(0) "" ["signature_format"]=> NULL ["picture"]=> string(1) "0" ["new"]=> int(0) ["comment_body"]=> array(1) { ["und"]=> array(1) { [0]=> array(3) { ["value"]=> string(235) 

[...]

What is the “readable” otion? I´ve read somewhere that print_r() is quite readable and ordered. But how can I understand what´s going on in there?

Any help will be very much appreciated!
Thanks!

How to&Answers:

try to preformat it for better readability:

echo "<pre>";
print_r($some_var);
echo "</pre>";

Answer:

Try this code:

<pre>
<?php
   print_r($content);
   var_dump($content);
?>
</pre>

Using <pre> tells your browser what is inside the block is already preformatted.

Answer:

I recommend you to install Xdebug php extension – it customizes var_dump() to colored HTML output.

Example:

$pages = PageQuery::create()->find();
var_dump($pages);die;

Output:

enter image description here