php dize operasyon

1 Cevap php

i html aşağıdaki kodu var

<? foreach($tst as $test) : ?>
<?=$test->id?>,
<? endforeach ?>

and that will result as test1,test2,test3,

nasıl basit usulde geçen virgül kaçının. Ben gibi html karmaşık kodu cant'kullanma

<? $i = 0 ;?>
<? foreach($tst as $test) : ?>
<?=$test->id?>,
<? endforeach ?>
<? $i++ ;?>
<? if($i != count($tst)) :?>
,
<?endif;?>
<? endforeach;?>

Lütfen Yardım :)

1 Cevap

implode, bir ara dizide kullanın:

<?php

$a= array();

foreach($tst as $test) {
 $a[]= $test->id;
}

echo(implode(', ', $a));

?>