echo
- Outputs one or more strings separated by commas
- No return valuee.g.
echo "String 1", "String 2"
print
- Outputs only a single string
- Returns
1, so it can be used in an expressione.g.print "Hello"or,if ($expr && print "foo")
print_r()
- Outputs a human-readable representation of any one value
- Accepts not just strings but other types including arrays and objects, formatting them to be readable
- Useful when debugging
- May return its output as a return value (instead of echoing) if the second optional argument is given
- There are two more functions similar to print_r() which are var_export(), and var_dump(). They display the private and protected properties of objects.
- print_r (mixed $var_name, boolean $return_output)
var_dump()
- Outputs a human-readable representation of one or more values separated by commas
- Accepts not just strings but other types including arrays and objects, formatting them to be readable
- Uses a different output format to
print_r(), for example it also prints the type of values - Useful when debugging
- No return value
var_export()
- Outputs a human-readable and PHP-executable representation of any one value
- Accepts not just strings but other types including arrays and objects, formatting them to be readable
- Uses a different output format to both
print_r()andvar_dump()- resulting output is valid PHP code! - Useful when debugging
- May return its output as a return value (instead of echoing) if the second optional argument is given
var_dump
hat dumps the information about the variables.
<?php
//PHP program to demonstrate the working of var_dump function
$x = 25;
//dump integer variable
var_dump ($x);
echo "</br>";
$y = 32.5;
//dump float variable
var_dump ($y);
echo "</br>";
$bvalue = true;
//dump boolean variable
var_dump ($bvalue);
?>
int(25)
float(32.5)
bool(true)
float(32.5)
bool(true)
<?php
//dump strings
$msg1 = "Hello Alex";
var_dump ($msg1);
echo "</br>";
$msg2 = "Welcome to javatpoint";
var_dump ($msg2);
?>
string(10) "Hello Alex"
string(21) "Welcome to javatpoint"
string(21) "Welcome to javatpoint"
No comments:
Post a Comment