开发者

What are some shorthand (but not necessarily safe) ways of displaying arrays in PHP?

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.


No, there is no easier way than this implode.


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜