开发者

basic question about php multiple FOREACH loops

I have few FOREACH loops in php;

开发者_如何学Python
$c1 = 1;
$c2 = 1;
$c3 = 1;

foreach ($someArray as $a){
    echo $a;
    if (sizeof($someArray != $c1){
        echo " / ";
    }
    $c1++;
}

foreach ($otherArray as $b){
    echo $b;
    if (sizeof($otherArray != $c2){
        echo ", ";
    }
    $c2++;
}

// etc.

This seems somehow stupid, of course =) Is there any way to avoid declaring variables with same values and to use them in many FOREACH loops? Thanks in advance for any help!


It appears you are trying to do what the following code does much better:

$line = implode(' / ', $someArray);
echo $line;

$line = implode(', ', $otherArray);
echo $line;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜