dongyanfeng0563 2016-04-17 05:17
浏览 33
已采纳

PHP - $ x = 0 - 为什么它等于1? [重复]

This question already has an answer here:

I have a few lines of code

$case=0;
file_put_contents("text.txt", $case, FILE_APPEND);
if ($case = 1)
{
    $message['a']="co"; 
}
if ($case = 0)
{
    $message['a']="to";
}
echo $message['a'];

It will echo "co". Why is this? The file_put contents puts "0". However the if statement thinks it is 1 for some reason...

</div>
  • 写回答

2条回答 默认 最新

  • douduonang3169 2016-04-17 05:18
    关注

    You are doing wrong in if condition. You doing assign instead of comparison.
    So here is the solution.

    $case=0;
    file_put_contents("text.txt", $case, FILE_APPEND);
    if ($case == 1)
    {
        $message['a']="co"; 
    }
    if ($case == 0)
    {
        $message['a']="to";
    }
    echo $message['a'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置