Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a pretty print for PHP?

I'm fixing some PHP scripts and I'm missing ruby's pretty printer. i.e.

require 'pp' arr = {:one => 1} pp arr 

will output {:one => 1}. This even works with fairly complex objects and makes digging into an unknown script much easier. Is there some way to duplicate this functionality in PHP?

like image 661
Aaron Lee Avatar asked Jul 22 '09 20:07

Aaron Lee


People also ask

What is print PHP?

PHP: print() function The print() function used to output one or more strings. The print() is not a real function, it is a language construct. Therefore there is no need to use parentheses with its argument list.

Where does PHP print to?

The docs say that these print to php://output . They are both language constructs, but at a guess, the difference is that print is an expression, but echo is a statement. printf and many friends.

Can we use print keyword in PHP?

The print keyword is used to output text. Unlike echo , print can only output one string at a time. Unlike echo , print has a return value, which is always 1.

What is pretty print in C?

Prettyprint can be done in many different ways. One of the basic implementations is code formatting, which splits blocks of code into individual code lines. Certain tools do this for various programming languages like LISP or C, making the result much more readable and conventional.


2 Answers

This is what I use to print my arrays:

<pre>     <?php         print_r($your_array);     ?> </pre> 

The magic comes with the pre tag.

like image 110
Joel Hernandez Avatar answered Sep 20 '22 00:09

Joel Hernandez


Both print_r() and var_dump() will output visual representations of objects within PHP.

$arr = array('one' => 1); print_r($arr); var_dump($arr); 
like image 40
Andrew Moore Avatar answered Sep 20 '22 00:09

Andrew Moore