00 Votes

PHP: Show content of array

Question by Guest | 2014-02-08 at 22:04

At the moment, I am working at a giant PHP script in which I am losing slowly but surely the overview.

For this reason, I've started to visualize my script a little bit by showing the contents of some variables with the PHP echo function, in order to understand what there is happening at all.

This method is working very good for integer and string vaiables. The only thing making problems are extensive arrays. So, is it somehow possible to echo or show an array in PHP in a simple and fast way? I do not want to go through the array using a foor loop because this is very inconvenient.

ReplyPositiveNegative
0Best Answer0 Votes

Just use the function print_r() from PHP.

This function outputs the content of an array:

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

print_r($arr);

The output could look something like this:

Array (
   [0] => 1
   [1] => 2
   [2] => 3
)

Of course, you can also get the same result using loops, but in fact this is a very inconvenient way if you only want to look in just one variable.
2014-02-09 at 10:51

ReplyPositive Negative
Reply

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.