When I echo var_dump($_variable), I get one long, wrapping line with all varable's and values like
["kt_login_user"]=> string(8) "teacher1" ["kt_login_id"]=> string(3) "973" ["kt_campusID"]=> string(4) "9088" ["kt_positionID"]=> string(1) "5"
Is there a way I can make each value display on its own line for ease of reading? Something like this:
["kt_login_user"]=> string(8) "teacher1" ["kt_login_id"]=> string(3) "973" ["kt_campusID"]=> string(4) "9088" ["kt_positionID"]=> string(1) "5"
The var-dump is display the datatype as well as value while echo only display the value. Explanation: In Php the var-dump function is used for displaying the datatype as well the value . The var-dump () does not return anythings it means there is no datatype of var-dump() function.
It's too simple. The var_dump() function displays structured information about variables/expressions including its type and value. Whereas The print_r() displays information about a variable in a way that's readable by humans. Example: Say we have got the following array and we want to display its contents.
var_dump() displays values along with data types as output. print_r() displays only value as output. It does not have any return type. It will return a value that is in string format.
4. Which is true about var_dump() function? Explanation: var_dump() cuts off loop after getting the same element three times is true about var_dump() function.
Yes, try wrapping it with <pre>
, e.g.:
echo '<pre>' , var_dump($variable) , '</pre>';
I usually have a nice function to handle output of an array, just to pretty it up a bit when debugging.
function pr($data) { echo "<pre>"; print_r($data); // or var_dump($data); echo "</pre>"; }
Then just call it
pr($array);
Or if you have an editor like that saves snippets so you can access them quicker instead of creating a function for each project you build or each page that requires just a quick test.
For print_r
:
echo "<pre>", print_r($data, 1), "</pre>";
For var_dump()
:
echo "<pre>", var_dump($data), "</pre>";
I use the above with PHP Storm. I have set it as a pr
tab command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With