00 Votes

PHP: How to show Content of Array in a quick way

Tip by NetLabel | 2016-06-15 at 12:24

When testing a PHP script, from time to time, you are coming at the point at which you just want to have a look into one of the variables - for example to check the assignment of an array.

Each time writing a function that is going through this array element for element in order to output every value is quite cumbersome. And there is a much more quicker and easier way to do so.

$arr = array(1,2,3,4);
 
print_r($arr);

var_dump($arr);

This example shows two possibilities with which you are able to display the content of the array $arr uncomplicated and straightforward. The PHP function print_r() as well as the function var_dump() are displaying each element of the array and can be used with arbitrary variable types.

Difference between var_dump and print_r

The difference between both functions lies in the details of the resulting information.

While print_r is only printing out the raw assignment of the array, var_dump is delivering detailed additional information about the used types, for example.

ReplyPositiveNegative

About the Author

AvatarThe author has not added a profile short description yet.
Show Profile

 

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.