dongqian5639 2014-11-11 16:54
浏览 36
已采纳

PHP get方法总是1? [关闭]

Why is the php get method value always 1? Here's my code.

echo isset($_GET['page']);
switch(isset($_GET['page'])){
    case 'a':
        echo '1';
        break;      
    case 'b':
        echo 2'';
        break;  
    case 'c':
        echo '3';
        break;          
    case 'd':
        echo '';
        break;          
    case 'e':
        echo '4';
        break;      
    default:
        echo '5';
}

And the value of the get method is always 1, showed in the first line code. Thanks for answering and helping me out to make a website.

  • 写回答

3条回答 默认 最新

  • douhengdao4499 2014-11-11 16:56
    关注
    isset($_GET['page'])
    

    isset returns true or false if $_GET['page'] is set. In this case php treats true as 1.

    Use the actual value:

    echo $_GET['page'];
    

    You can check if it's set which is likely what you intended:

    if(isset($_GET['page'])){
        //Do stuff with $_GET['page']
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题