Php 在url参数上返回0/1

Php 在url参数上返回0/1,php,function,url,Php,Function,Url,我需要一些帮助。 我想创建一个php文件,在使用url参数打开文件时返回0或1 到目前为止,我有以下代码: <?php function checkID($ID) { $allowedID = array('111','123'); if (in_array($ID, $allowedID )) echo '1'; else echo '0'; } ?> 当我打开文件时,它只显示一个空白页。 我不知道如何使用url参数,比如site.com/myphp.php?ID=11

我需要一些帮助。 我想创建一个php文件,在使用url参数打开文件时返回0或1

到目前为止,我有以下代码:

<?php
function checkID($ID)
{
$allowedID = array('111','123');
if (in_array($ID, $allowedID ))
echo '1';
else
echo '0';   
}
?>

当我打开文件时,它只显示一个空白页。 我不知道如何使用url参数,比如site.com/myphp.php?ID=111

谢谢


<?php
function checkID($ID)
{
    $allowedID = array('111','123');
    if (in_array($ID, $allowedID)) {
        echo '1';
    } else {
        echo '0';   
    }
}
checkID($_GET['ID']); 
?>

您需要检查ID是否在$\u GET数组中,然后检查它是否与您定义的集合匹配:

function checkID()
{
    $allowedID = array('111','123');
    if (array_key_exists('ID', $_GET) && in_array($_GET['ID'], $allowedID )) {
        return '1';
    } else {
        return '0';   
    }
}

// run the function
echo checkID();

编辑-从函数中删除参数并回显结果

那么您如何调用checkID()函数呢?您的函数调用没有参数。您可能还希望回显刚刚更改的结果返回回显,结果正常。谢谢!!谢谢,它可以工作,但是当ID被允许时,页面是空白的。