English 中文(简体)
PHP 双环添加 2 时的 PHP
原标题: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

对于那些寻求加薪对数(如1-2至3-4)的人:

解决方案一:

//initial values
$n_left = 1;
$n_right = 2;

for ($i = 1; $i <= 5; $i++) {
    
    print "
" . $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 "
" . ($y+1) . "-" . ($y+2);  

}
//result: 1-2 3-4 5-6 7-8 9-10




相关问题
What does it mean "to write a web service"?

I just asked a question about whether it was possible to write a web-page-checking code and run it from free web server, and one supporter answered and said that it was possible only if I run "a web ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Why does Scala create a ~/tmp directory when I run a script?

When I execute a Scala script from the command line, a directory named "tmp" is created in my home directory. It is always empty, so I simply deleted it without any apparent problem. Of course, when I ...

Ivy, ant and start scripts

I have a project that uses ant to build and ivy for dependencies. I would like to generate the start scripts for my project, with the classpath, based on the dependencies configured in Ivy, ...

热门标签