Laravel

Laravel print_r(), var_dump() and dd()

Share your learning

Hey dude, today we are going to understand about Laravel print_r, var_dump and dd, all are very helpful in terms of debugging in Laravel.

To figure out the error we always trying to view the variables. With Laravel, we can use dd() ( a combination of the dump and die ) to debug the program.

Why do we need to use var_dump?

Why we need to use Laravel var_dump (), when we have print_r (), dd(), dump() and die() for debugging.

Well, Let’s assume,

We want to know the data type of the variable with value at some point of debugging. Then we can use var_dump($variable) it will return something like this

(int) 5
(string) ‘testcase’

I don’t recommend to use var_dump() to view the Laravel collection. Because we have amazing methods print_r() and dd()  for that.

You don’t need to use var_dump() unless you want to see the data type of the variable.

Why do we need to use print_r?

With dd(), We have to expand the object and then we can see a different level of data in the object.

We can use CTRL+Click on windows and CMD+click on mac to expand all data at once.

To avoid this limitation we can use print_r() which give us a nice expanded array.

Even we can use pre HTML tag to prettify the array data.

We can also use toArray() helper function to convert Laravel collection into an array.

Satpal

Recent Posts

How to Switch PHP Versions in XAMPP Easily: Managing Multiple PHP Versions on Ubuntu

Today we are going to learn about managing multiple PHP versions on ubuntu with xampp.…

1 year ago

How to Use Coding to Improve Your Website’s SEO Ranking?

Let's understand about how to use coding to improve your website's SEO. In today’s computerized…

1 year ago

Most Important Linux Commands for Web Developers

Let's understand the most important linux commands for web developers. Linux, as an open-source and…

1 year ago

Top 75+ Laravel Interview Questions Asked by Top MNCs

Today we are going to discuss top 75+ Laravel interview questions asked by top MNCs.Laravel,…

1 year ago

Mailtrap Integration for Email Testing with Laravel 10

Today we will discuss about the Mailtrap integration with laravel 10 .Sending and receiving emails…

1 year ago

Firebase Cloud Messaging (FCM) with Ionic 6: Push Notifications

Today we are going to integrate FCM (Firebase Cloud Messaging) push notifications with ionic application.Firebase…

1 year ago