Hello,

I have come across these echo types before:
echo
print_r
printf
var_dump

But now come across:
var_export.
https://www.w3schools.com/php/phptryit.asp?filename=tryphp_func_var_var_export

$a = 32;
echo var_export($a) . "<br>";

$b = "Hello world!";
echo var_export($b) . "<br>";

$c = 32.5;
echo var_export($c) . "<br>";

$d = array("red", "green", "blue");
echo var_export($d) . "<br>";

$e = array(32, "Hello world!", 32.5, array("red", "green", "blue"));
echo var_export($e) . "<br>";

When would you use any of these over the others and why ?
How does var_export become handy ?
Do show me some examples to understand.

Thanks

The main use cases for var_dump() and var_export() would be for debugging purposes or logging errors.

When debugging your code, you might want to be able to spit out the structure and contents of an array or object to understand what went wrong.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.