• 14-10-2010, 22:18:25
    #1
    merhaba arkadaşlar aşağıdaki foreach döngüsü aracılığıyla aşağıdaki çıktıyı elde ediyorum. yanlız en sondaki döngünün sondaki süslü parentezin sonunda bulunan virgülün çıkmasını istemiyorum. ne yapabilirim ? yardımcı olursanız sevinirim...

    Foreach Döngüsü

    foreach ($resim_c as $res) 
    {
    echo $res['id'].': {image: "'. $res[’image']. ’"}';
    if($res['id'] != end($res))
    echo ','; 
    }
    Döngünün çıktısı

    673: {image: "10494"},
    6674: {image: "10495"},
    6668: {image: "10472"},
    6671: {image: "10475"},
    6669: {image: "10473"},
    6672: {image: "10476"},
    6664: {image: "10469"},
    6666: {image: "10471"},
    6670: {image: "10474"},
    6665: {image: "10470"},
  • 14-10-2010, 22:35:56
    #2
    $tmp = count($resim_c) - 1;
    foreach ($resim_c as $k => $res) 
    {
    echo $res['id'].': {image: "'. $res['image']. '"}' . ($tmp == $k ? '' : ',') ;
    }
  • 15-10-2010, 09:50:08
    #3
    Üyeliği durduruldu
    $elements = array();
    
        foreach ($resim_c as $res) 
        {
           $elements[] =  $res['id'].': {image: "'. $res['image']. '"}';
        }
        
    echo implode(",\n",$elements);
    boyle de deneyebilirsiniz.