Outputting data in PHP: print vs echo vs printf vs var_dump vs print_r
PHP provides us with many ways to output data onto a screen. Most of the time PHP developers use these built-in functions interchangeably. Each function has a specific use-case and by the end of this article you will know how to properly use them.
Difference between print, echo and printf vs var_dump and print_r
var_dump and print_r are specifically used to output variables while print, printf and echo are used to output strings that can include concatenation, variables and HTML.
What is var_dump?
The var_dump function basically “dumps information about a variable” in a structured format. This function can also accept multiple arguments.
Code:
$b = 3.1;
$c = true;
var_dump($b, $c);
Output:
float(3.1)
bool(true)
What is print_r?
The print_r function “prints human-readable information about a variable”. This function as to parameters. One for the expression to be printed and the other for returning the output. If set to TRUE this function will will return the…