PHP Variables Dump


 

PHP Variables Dump

There are some moments in our application when we face some problems or we work on someone else project the first thing we do is to check the detail of the contents or application either it is an array or object in php.

There are some moments in our application when we face some problems or we work on someone else project the first thing we do is to check the detail of the contents or application either it is an array or object in php.

PHP Variables Dump

There are some moments in our application when we face some problems or we work on someone else project the first thing we do is to check the detail of the contents or application either it is an array or object in php. We use var_dump( ) to show the variable type, its value and if it an object or array. The biggest disadvantage of using var_dump( ) is that the output is shown in the URL. For example :

<?php

$user['emp_id'] = "1";

$user['name'] = "Suraj Mittal";

$user['age'] = "22";

$user['salary'] = "15000";

var_dump($user);

?>


The output of the above example is : array(4) { ["emp_id"]=> string(1) "1" ["name"]=> string(12) "Suraj Mittal" ["age"]=> string(2) "22" ["salary"]=> string(5) "15000" }

The above example showed the entire information about the variable. So, the programmer can easily understand the whole code and also know it is an object or array and how many objects and array are created. Even you can also get the information about the string, integers, float and so on. Let see another example where we use integers and string both :

<?php

$emp = array(1, 2, array("Suraj", "NOOR", "RAVI"));

var_dump($emp);

?>

 The output of the above example is : array(3) { [0]=> int(1)

                                                                        [1]=> int(2)

                                                                        [2]=> array(3) {

                                                                        [0]=> string(5) "Suraj"

                                                                        [1]=> string(4) "NOOR"

                                                                        [2]=> string(4) "RAVI"

                                                                        }

                                                                     }

 

Ads