看板 PHP 關於我們 聯絡資訊
我想做到以下功能,不知道程式碼要怎樣寫呢? 第一次回圈 $temp=1 第二次回圈 $temp=1|2 第三次回圈 $temp=1|2|3 第四次回圈 $temp=1|2|3|4 要做到這樣,要怎樣撰寫呢? 因為我寫出來幾乎都是相加起來的結果 $temp=10 ~''~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.193.226.242
star508 :while($i<5){$j=($i)?'|':'';$temp.=($i+1).$j;$i++} 10/31 22:24
star508 :while($i<5){$j=($i)?'|':'';$temp.=$j.($i+1);$i++; 10/31 22:33
star508 :} 這樣才對 10/31 22:33
star508 :while(++$i<5){$j=($i==1)?'':'|';$temp.=$j.$i;}; 10/31 22:39
star508 :前三行當做沒看到吧:) 10/31 22:40
liaosankai :$temp=range(1,5);$temp=join('|',$temp); 11/01 07:54
liaosankai :如果你的數字是連續性的,上面1行就解決了 11/01 07:55
buganini :要不要轉CodeJob? 09/15 00:44