One of the common debugging option still remains in PHP is to print the values in the browser using print_r()
or var_dump()
.
var_dump()
usually dumps all the related information about a variable or object on the same page where we call the var_dump. The key feature here to note is, it will not stop the execution of the script. That’s the same case with print_r() but the latter will not show the type of the variable. You can observe the difference in the below picture and code.
<?php $fruits = array( 'Apple'=>6, 'Kiwi'=>10, 'Orange'=>4 ); var_dump($fruits); echo "<br>I comes after fruits"; ?>
But Laravel developers are blessed with a different function to evaluate further, and that’s called dd()
or dump and die. You can use this helper function anywhere in the application, even this will work in the blade templates as well.
This function is considered a really cool debugging option with color-coded variables and objects, which is very readable and well-formatted.
- Just want to thank us? Buy us a Coffee
- May be another day? Shop on Amazon using our links.
Your prices won't change but we get a small commission.