By leoman730 on
Hi guys,
I have a question on the print_r() method. I know that we can used this function to print out an array. My problem is if i got too many elements in the array, the print_r() could not return a nice look print out. For example:
print_r($array) may have result of:
Array ( [514] => stdClass Object ( [cookie_id] => 1 [nid] => 514 [qty] => 2 [changed] => 1183484115 [data] => 7362 [vid] => 514 [pparent] => 0 [sku] => [price] => 342.55 [ptype] => tangible [hide_cart_link] => 0 [stock] => 7 [manage_stock] => 1 [availability] => 1 [original_price] => 527.00 )
but what i want is something looks like this:
Array(
[514] => stdClass Object (
[cookie_id] => 1
[nid] => 514
[qty] => 2...
)
[data]=> 7362
...
Anyone have clue how to do it?
Thanks.
Comments
Use pre tag
echo '<pre>'; print_r($array); echo '</pre>';View Source, or dprint_r
If you view the source of the page, you should be able to see structured version of the output, which is probably what you want.
If it absolutely has to appear formatted in the standard browser view of the page, you can try a couple of things, like:
Or, you could use the dprint_r function in the devel module, though that's probably overkill for just the one function. Still, it does a nice job of formatting the output.
And just one more tip... I
And just one more tip... I use the following all the time in my modules to debug different parts:
I use it so much I should create a keyboard key just for that string. : P
----------------------
Current Drupal project: http://www.ubercart.org
Great tip
Great tip rszrama! Thanks!
Try this
Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database
NancyDru
hi, can you explain how to
hi,
can you explain how to use that function?
thanks
It goes into a module
It goes into a module. Then you call it with the name of an array. It will produce a table showing the values recursed down to the bottom.
Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database
NancyDru