[英]PHP while loop add by 2
目前我有一個看起來像這樣的代碼:
for ($i=0; $i<=($num_newlines - 1); $i++)
{
$tweetcpitems->post('statuses/update',
array('status' => wordFilter("The item $parts[$i] has been released on Club Penguin. View it here: http://clubpenguincheatsnow.com/tools/swfviewer/items.swf?id=$parts[$id]")));
sleep(90);
}
我想做的是使“i++”部分加二而不是加一,但我該怎么做呢? 請幫忙!
for ($i=0; $i<=($num_newlines - 1); $i+=2) {
$i++ : increment by one
$i+=2 : increment by two
$i+=3 : increment by three
ETC..
對於那些希望增加一對數字(如 1-2 到 3-4)的人:
解決方案一:
//initial values
$n_left = 1;
$n_right = 2;
for ($i = 1; $i <= 5; $i++) {
print "\n" . $n_left . "-" . $n_right;
$n_left =+ $n_left+2;
$n_right =+ $n_right+2;
}
//result: 1-2 3-4 5-6 7-8 9-10
解決方案二:
for ($y = 0; $y <= 9; $y+=2) {
print "\n" . ($y+1) . "-" . ($y+2);
}
//result: 1-2 3-4 5-6 7-8 9-10
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.