PHP counter increment in a while loop

前端 未结 5 1956
一生所求
一生所求 2021-01-29 08:33

Im having a problem incrementing a counter in one of my while loops basically i just want to alternate between two image links that were fetched in my database but my counter wo

5条回答
  •  一向
    一向 (楼主)
    2021-01-29 09:13

    $i  = 0;
    while($i<5) {
        $alternateVal   = $i%2==0 ? "type1" : "type2";
        echo $alternateVal;
        $i++;
    }
    

    Above is an example to overview alternate values.

提交回复
热议问题