Is there an easy way to print the items of an array without using print_r or var_dump and without using any loops?
I don't want to show key to value relationship like var_dump and print_r shows.... just the items in the array. And no loops...
$array = array(1,2,3,4,5);
Let's say there's a function called: print_array
Then I would do this:
And it would spit out: 1 2 3 4 5
I checked out PHP.net but didn't see anything under the print_r function...maybe one of you guys know of some other function?
There might be a premade function for it, but a simple for each loop would do the trick. Its hardly a wheel to reinvent.
right, I know, I want to avoid any loops, I'm working on a pagination script and I have an idea about how to do something but I didn't want to use loops because I wanted to keep it clean and straightforward.
In any event, I'll have to just make my own function that should be able to spit it right out the way I wanted...
lol, that is exactly what I was looking to do, hoping PHP had a simple built in function but guess not. I will need to incorporate this into my paginate function, then you'll see what I was trying to do...
Originally Posted by Brook
<pre><?php print_r($array); ?></pre>
No, print_r and var_dump provides a very un-elegant printout.
Look at tanax's example, that is what I was looking for but wanted to make sure that PHP didn't have something like this already built in..
Why would you want to extend echoing an array's values, with more functionality?!
I don't know.
For instance, he might want to run an if-statement to check something on each element. Add something around each element. Well.. you get the point. But since he just wanted to echo out the array(at least right now) - imploding the array will work great.