Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用IF语句以1的增量自动增加数字?_Php - Fatal编程技术网

Php 如何使用IF语句以1的增量自动增加数字?

Php 如何使用IF语句以1的增量自动增加数字?,php,Php,我试图回应一个可变的数字,但我不确定最好的方法。我的问题是: 我有一系列的“如果”条件,我相应地回显一个变量 if ($month == "8" || $month == "9" || $month == "10") { $comingseason = 'winter'; $elementsDue = "Due October 31, " . $year . ", for our " . $comingseason . " issue No. 9"; } else

我试图回应一个可变的数字,但我不确定最好的方法。我的问题是:

我有一系列的“如果”条件,我相应地回显一个变量

   if ($month == "8" || $month == "9" || $month == "10") {
    $comingseason   = 'winter';
    $elementsDue    = "Due October 31, " . $year . ", for our " . $comingseason . " issue No. 9";
}
else if ($month == "11" || $month == "12" || $month == "1") {
    $comingseason   = 'spring';
    $elementsDue    = "Due January 31, " . ++$year . ", for our " . $comingseason . " issue No. 9";
}
else if ($month == "2" || $month == "3" || $month == "4") {
    $comingseason   = 'summer';
    $elementsDue    = "Due April 30, " . $year . ", for our " . $comingseason . " issue No. 9";
}
else if ($month == "5" || $month == "6" || $month == "7") {
    $comingseason   = 'fall';
    $elementsDue    = "Due July 31, " . ++$year . ", for our " . $comingseason . " issue No. 9";
}
我想知道我将如何用下一个增量++1替换“第9期”中的数字,以输出“10”?我不想每次都要回到代码中,输入下一期的编号。我希望这个数字能自行增加,基本上是每个季度都会增加,就像你在下面看到的那样

我在考虑一个php会话,但据我所知,它不会是永久的。我需要在用户结束会话后保留该号码


我怎样才能做到这一点

也许你在找这个

说明:添加一个整数变量,比如$issuNo,然后再添加该变量的初始值。然后,在if/else条件块之后,放入类似$issuNo++的增量变量,然后最好编写一个程序,稍后继续执行if/else语句

$issuNo = 9;     
if ($month == "8" || $month == "9" || $month == "10") {
        $comingseason   = 'winter';
        $elementsDue    = "Due October 31, " . $year . ", for our " . $comingseason . " issue No. ".$issuNo;
    }
    else if ($month == "11" || $month == "12" || $month == "1") {
        $comingseason   = 'spring';
        $elementsDue    = "Due January 31, " . ++$year . ", for our " . $comingseason . " issue No. ".$issuNo;
    }
    else if ($month == "2" || $month == "3" || $month == "4") {
        $comingseason   = 'summer';
        $elementsDue    = "Due April 30, " . $year . ", for our " . $comingseason . " issue No. ".$issuNo;
    }
    else if ($month == "5" || $month == "6" || $month == "7") {
        $comingseason   = 'fall';
        $elementsDue    = "Due July 31, " . ++$year . ", for our " . $comingseason . " issue No. ".$issuNo;
    }
$issuNo++;

也许你在找这个

说明:添加一个整数变量,比如$issuNo,然后再添加该变量的初始值。然后,在if/else条件块之后,放入类似$issuNo++的增量变量,然后最好编写一个程序,稍后继续执行if/else语句

$issuNo = 9;     
if ($month == "8" || $month == "9" || $month == "10") {
        $comingseason   = 'winter';
        $elementsDue    = "Due October 31, " . $year . ", for our " . $comingseason . " issue No. ".$issuNo;
    }
    else if ($month == "11" || $month == "12" || $month == "1") {
        $comingseason   = 'spring';
        $elementsDue    = "Due January 31, " . ++$year . ", for our " . $comingseason . " issue No. ".$issuNo;
    }
    else if ($month == "2" || $month == "3" || $month == "4") {
        $comingseason   = 'summer';
        $elementsDue    = "Due April 30, " . $year . ", for our " . $comingseason . " issue No. ".$issuNo;
    }
    else if ($month == "5" || $month == "6" || $month == "7") {
        $comingseason   = 'fall';
        $elementsDue    = "Due July 31, " . ++$year . ", for our " . $comingseason . " issue No. ".$issuNo;
    }
$issuNo++;

也许你在找这个

说明:添加一个整数变量,比如$issuNo,然后再添加该变量的初始值。然后,在if/else条件块之后,放入类似$issuNo++的增量变量,然后最好编写一个程序,稍后继续执行if/else语句

$issuNo = 9;     
if ($month == "8" || $month == "9" || $month == "10") {
        $comingseason   = 'winter';
        $elementsDue    = "Due October 31, " . $year . ", for our " . $comingseason . " issue No. ".$issuNo;
    }
    else if ($month == "11" || $month == "12" || $month == "1") {
        $comingseason   = 'spring';
        $elementsDue    = "Due January 31, " . ++$year . ", for our " . $comingseason . " issue No. ".$issuNo;
    }
    else if ($month == "2" || $month == "3" || $month == "4") {
        $comingseason   = 'summer';
        $elementsDue    = "Due April 30, " . $year . ", for our " . $comingseason . " issue No. ".$issuNo;
    }
    else if ($month == "5" || $month == "6" || $month == "7") {
        $comingseason   = 'fall';
        $elementsDue    = "Due July 31, " . ++$year . ", for our " . $comingseason . " issue No. ".$issuNo;
    }
$issuNo++;

也许你在找这个

说明:添加一个整数变量,比如$issuNo,然后再添加该变量的初始值。然后,在if/else条件块之后,放入类似$issuNo++的增量变量,然后最好编写一个程序,稍后继续执行if/else语句

$issuNo = 9;     
if ($month == "8" || $month == "9" || $month == "10") {
        $comingseason   = 'winter';
        $elementsDue    = "Due October 31, " . $year . ", for our " . $comingseason . " issue No. ".$issuNo;
    }
    else if ($month == "11" || $month == "12" || $month == "1") {
        $comingseason   = 'spring';
        $elementsDue    = "Due January 31, " . ++$year . ", for our " . $comingseason . " issue No. ".$issuNo;
    }
    else if ($month == "2" || $month == "3" || $month == "4") {
        $comingseason   = 'summer';
        $elementsDue    = "Due April 30, " . $year . ", for our " . $comingseason . " issue No. ".$issuNo;
    }
    else if ($month == "5" || $month == "6" || $month == "7") {
        $comingseason   = 'fall';
        $elementsDue    = "Due July 31, " . ++$year . ", for our " . $comingseason . " issue No. ".$issuNo;
    }
$issuNo++;

这似乎是一个很简单的问题。我建议读一本好的入门级PHP编程书。话虽如此,您需要设置
while
循环和一些嵌套的
if-else
条件

$month = 0;

while ($month < 12) {
    $month++;

    If ($month > 7 && $month < 11)
    { 
        $comingsoon = "winter";
    }
    elseif 
    {
        some logic
    }
    elseif
    {
        some logic
    }
    else
    {

    }
} # end of while loop
$month=0;
而($month<12){
$month++;
如果($month>7&&$month<11)
{ 
$comingsoon=“冬季”;
}
埃尔塞夫
{
一些逻辑
}
埃尔塞夫
{
一些逻辑
}
其他的
{
}
}#while循环结束

我有意将剩下的代码留给您编写。学习一些编码对你来说是一个很好的练习:)祝你好运

好的,这似乎是一个很容易解决的问题。我建议读一本好的入门级PHP编程书。话虽如此,您需要设置
while
循环和一些嵌套的
if-else
条件

$month = 0;

while ($month < 12) {
    $month++;

    If ($month > 7 && $month < 11)
    { 
        $comingsoon = "winter";
    }
    elseif 
    {
        some logic
    }
    elseif
    {
        some logic
    }
    else
    {

    }
} # end of while loop
$month=0;
而($month<12){
$month++;
如果($month>7&&$month<11)
{ 
$comingsoon=“冬季”;
}
埃尔塞夫
{
一些逻辑
}
埃尔塞夫
{
一些逻辑
}
其他的
{
}
}#while循环结束

我有意将剩下的代码留给您编写。学习一些编码对你来说是一个很好的练习:)祝你好运

好的,这似乎是一个很容易解决的问题。我建议读一本好的入门级PHP编程书。话虽如此,您需要设置
while
循环和一些嵌套的
if-else
条件

$month = 0;

while ($month < 12) {
    $month++;

    If ($month > 7 && $month < 11)
    { 
        $comingsoon = "winter";
    }
    elseif 
    {
        some logic
    }
    elseif
    {
        some logic
    }
    else
    {

    }
} # end of while loop
$month=0;
而($month<12){
$month++;
如果($month>7&&$month<11)
{ 
$comingsoon=“冬季”;
}
埃尔塞夫
{
一些逻辑
}
埃尔塞夫
{
一些逻辑
}
其他的
{
}
}#while循环结束

我有意将剩下的代码留给您编写。学习一些编码对你来说是一个很好的练习:)祝你好运

好的,这似乎是一个很容易解决的问题。我建议读一本好的入门级PHP编程书。话虽如此,您需要设置
while
循环和一些嵌套的
if-else
条件

$month = 0;

while ($month < 12) {
    $month++;

    If ($month > 7 && $month < 11)
    { 
        $comingsoon = "winter";
    }
    elseif 
    {
        some logic
    }
    elseif
    {
        some logic
    }
    else
    {

    }
} # end of while loop
$month=0;
而($month<12){
$month++;
如果($month>7&&$month<11)
{ 
$comingsoon=“冬季”;
}
埃尔塞夫
{
一些逻辑
}
埃尔塞夫
{
一些逻辑
}
其他的
{
}
}#while循环结束

我有意将剩下的代码留给您编写。学习一些编码对你来说是一个很好的练习:)祝你好运

在我看来,问题是年和季度的函数:从某个基准年/季度开始,每个季度有一个问题。因此,类似这样的东西应该会自动计算它(您必须使用$base_year和$base_qtr使其与您的发行编号匹配)


在我看来,问题是年和季度的函数:从某个基准年/季度开始,每个季度有一个问题。因此,类似这样的东西应该会自动计算它(您必须使用$base_year和$base_qtr使其与您的发行编号匹配)


在我看来,问题是年和季度的函数:从某个基准年/季度开始,每个季度有一个问题。因此,类似这样的东西应该会自动计算它(您必须使用$base_year和$base_qtr使其与您的发行编号匹配)


在我看来,问题是年和季度的函数:从某个基准年/季度开始,每个季度有一个问题。因此,类似这样的东西应该会自动计算它(您必须使用$base_year和$base_qtr使其与您的发行编号匹配)


如果这是您正在寻找的:

<?php

$month = '3';
$year = '2015';
$issue = 9;
 if ($month == "8" || $month == "9" || $month == "10") {
    $comingseason   = 'winter';
 echo   $elementsDue    = "Due October 31, " . $year . ", for our " . $comingseason . " issue No. $issue";
}
else if ($month == "11" || $month == "12" || $month == "1") {
    $comingseason   = 'spring';
        $issue = $issue + 1;

echo    $elementsDue    = "Due January 31, " . ++$year . ", for our " . $comingseason . " issue No. $issue";
}
else if ($month == "2" || $month == "3" || $month == "4") {
    $comingseason   = 'summer';
        $issue = $issue + 2;
echo    $elementsDue    = "Due April 30, " . $year . ", for our " . $comingseason . " issue No. $issue";
}
else if ($month == "5" || $month == "6" || $month == "7") {
    $comingseason   = 'fall';
    $issue = $issue + 3;
echo    $elementsDue    = "Due July 31, " . ++$year . ", for our " . $comingseason . " issue No. $issue";
}
?>


如果这是您想要的:

<?php

$month = '3';
$year = '2015';
$issue = 9;
 if ($month == "8" || $month == "9" || $month == "10") {
    $comingseason   = 'winter';
 echo   $elementsDue    = "Due October 31, " . $year . ", for our " . $comingseason . " issue No. $issue";
}
else if ($month == "11" || $month == "12" || $month == "1") {
    $comingseason   = 'spring';
        $issue = $issue + 1;

echo    $elementsDue    = "Due January 31, " . ++$year . ", for our " . $comingseason . " issue No. $issue";
}
else if ($month == "2" || $month == "3" || $month == "4") {
    $comingseason   = 'summer';
        $issue = $issue + 2;
echo    $elementsDue    = "Due April 30, " . $year . ", for our " . $comingseason . " issue No. $issue";
}
else if ($month == "5" || $month == "6" || $month == "7") {
    $comingseason   = 'fall';
    $issue = $issue + 3;
echo    $elementsDue    = "Due July 31, " . ++$year . ", for our " . $comingseason . " issue No. $issue";
}
?>


如果这是您想要的:

<?php

$month = '3';
$year = '2015';
$issue = 9;
 if ($month == "8" || $month == "9" || $month == "10") {
    $comingseason   = 'winter';
 echo   $elementsDue    = "Due October 31, " . $year . ", for our " . $comingseason . " issue No. $issue";
}
else if ($month == "11" || $month == "12" || $month == "1") {
    $comingseason   = 'spring';
        $issue = $issue + 1;

echo    $elementsDue    = "Due January 31, " . ++$year . ", for our " . $comingseason . " issue No. $issue";
}
else if ($month == "2" || $month == "3" || $month == "4") {
    $comingseason   = 'summer';
        $issue = $issue + 2;
echo    $elementsDue    = "Due April 30, " . $year . ", for our " . $comingseason . " issue No. $issue";
}
else if ($month == "5" || $month == "6" || $month == "7") {
    $comingseason   = 'fall';
    $issue = $issue + 3;
echo    $elementsDue    = "Due July 31, " . ++$year . ", for our " . $comingseason . " issue No. $issue";
}
?>


如果这是您想要的:

<?php

$month = '3';
$year = '2015';
$issue = 9;
 if ($month == "8" || $month == "9" || $month == "10") {
    $comingseason   = 'winter';
 echo   $elementsDue    = "Due October 31, " . $year . ", for our " . $comingseason . " issue No. $issue";
}
else if ($month == "11" || $month == "12" || $month == "1") {
    $comingseason   = 'spring';
        $issue = $issue + 1;

echo    $elementsDue    = "Due January 31, " . ++$year . ", for our " . $comingseason . " issue No. $issue";
}
else if ($month == "2" || $month == "3" || $month == "4") {
    $comingseason   = 'summer';
        $issue = $issue + 2;
echo    $elementsDue    = "Due April 30, " . $year . ", for our " . $comingseason . " issue No. $issue";
}
else if ($month == "5" || $month == "6" || $month == "7") {
    $comingseason   = 'fall';
    $issue = $issue + 3;
echo    $elementsDue    = "Due July 31, " . ++$year . ", for our " . $comingseason . " issue No. $issue";
}
?>

从“其他”开始