php birden foreach döngüleri ile ilgili temel soru

1 Cevap

Ben php birkaç foreach döngüleri var;

$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!

1 Cevap

Bu aşağıdaki kod çok daha iyi ne yapmaya çalıştığınız anlaşılıyor:

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

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