Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

variables

php

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!

like image 299
Rosamunda Avatar asked Aug 16 '12 21:08

Rosamunda


People also ask

What is the difference between Var_dump () and Print_r ()?

var_dump() displays values along with data types as output. print_r() displays only value as output. It does not have any return type. It will return a value that is in string format.

What value will Var_dump show that Echo will not show?

The var-dump is display the datatype as well as value while echo only display the value. Explanation: In Php the var-dump function is used for displaying the datatype as well the value . The var-dump () does not return anythings it means there is no datatype of var-dump() function.

What is Var_dump () used for?

The var_dump() function dumps information about one or more variables. The information holds type and value of the variable(s).

What does Print_r do in PHP?

Definition and Usage The print_r() function prints the information about a variable in a more human-readable way.


2 Answers

try to preformat it for better readability:

echo "<pre>";
print_r($some_var);
echo "</pre>";
like image 98
raidenace Avatar answered Sep 30 '22 04:09

raidenace


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.

like image 31
Jocelyn Avatar answered Sep 30 '22 04:09

Jocelyn