Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.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-“文件”;否则";即使存在另一个“时也会执行”;elseif“;因为我';我正在努力_Php - Fatal编程技术网

PHP-“文件”;否则";即使存在另一个“时也会执行”;elseif“;因为我';我正在努力

PHP-“文件”;否则";即使存在另一个“时也会执行”;elseif“;因为我';我正在努力,php,Php,我试图用php实现这一点: <?php $link = $_GET['link']; $sayi = strlen($link); $list = array(something here) if (in_array($link, $list)) { some code here 1 } elseif($sayi == "0")

我试图用php实现这一点:

        <?php
        $link = $_GET['link'];
        $sayi = strlen($link);
        $list = array(something here)
        if (in_array($link, $list)) 
        {
          some code here 1
        }
        elseif($sayi == "0")
        {
          some code here 2
        }
        if($sayi != "11" AND $sayi != "0")
        {
          some code here 3  
        }
        else
        {
          some code here 4  
        }
?>

当我尝试使用空白的$link时,它通常只会执行“somecode here 2”。我不理解我的错误,但它同时执行“这里的一些代码2”和“这里的一些代码4”

我做错了什么?提前感谢,我对php还很陌生(2天新吗?:)


天啊,我觉得自己很傻。如果可以,我会接受你的答案(时间限制)

你有两个独立的if条件,根据你的代码,输出是正确的。您必须将代码更改为下面的

if (in_array($link, $list)) 
        {
          some code here 1
        }
        elseif($sayi == "0")
        {
          some code here 2
        }
        else if($sayi != "11" AND $sayi != "0")// add else here
        {
          some code here 3  
        }
        else
        {
          some code here 4  
        }

有两个独立的代码段正在求值,一个
IF
及其
ELSEIF
,然后另一个
IF
及其自己的
ELSE
。如果只想检查一次条件,则必须连续执行
ELSEIFs

$link = $_GET['link'];
        $sayi = strlen($link);
        $list = array(something here)
        if (in_array($link, $list)) 
        {
          some code here 1
        }
        elseif($sayi == 0)
        {
          some code here 2
        }
        elseif($sayi != 11 AND $sayi != 0)
        {
          some code here 3  
        }
        else // If NONE of previous conditional is true, then execute this.
        {
          some code here 4  
        }
?>

您需要用elseif替换第二个if,如下所示:

<?php

$link = $_GET['link'];
$sayi = strlen($link);
$list = array(something here)
if (in_array($link, $list)) 
{
  some code here 1
}
elseif($sayi == 0)
{
  some code here 2
}
elseif($sayi != 11)
{
  some code here 3  
}
else
{
  some code here 4  
}

你想做什么?

首先,您应该使用“if($sayi==0)”中的比较。即使在“$sayi==11”或“$sayi==0”之后,始终会打印“此处的某些代码4”。

如果您选中具有整数的“
$sayi
”,则会在第二秒内打印。strlen返回int()