tags:

views:

112

answers:

4

I have tried to do this:

<?=implode(array('A','B','C'));

To display an array but was wondering if there was an easier way of showing an array?

I tried

<?=print_r(array('A','B','C'));

But it actually displays an array structure. I want the string to be like ABC.

+3  A: 

No, there is no easier way than this implode.

Anti Veeranna
There is a shorter way: join()! ;)
Alix Axel
of course :) 3 bytes shorter :)
Anti Veeranna
Right when you mentioned "join" I noticed it on the implode page on php.net. lol. Thanks!
Daniel
A: 

Normally while debugging array printing is done using implode() and print_r(). If you want to display the arrays in your different way, just create your own function for that.

Andrejs Cainikovs
A: 

I have seen in many examples var_dump(...). link text

dimitris mistriotis
A: 

Yeah, sure... If you always want an array to display, say, with each element on a new line, you can just write your own function (with a really short name... if you are just that lazy... [not recommended...])!

<?php
// To Call Function:
$array = array(2,3,4,5,'awesome!');
ez($array);

/* echoes:
 2
 3
 4
 5
 awesome!
*/

// Poorly named function...
function ez($array = array()) {
    if(!$array || empty($array)) return;
    $output = implode('\n',$array);
    echo "<pre>{$output}</pre>";
}
?>

Sorry, this is kind of a smartass answer.

KyleFarris