未定义的索引(PHP) [英] Undefined index (PHP)

查看:514
本文介绍了未定义的索引(PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要一些解释。
我的表格如下:

Need some explanation. I made form as following:

<form action="test4.php" method="post">
    <select name="code">
        <option value="A">A</option>
        <option value="B">B</option>
        <option value="C">C</option>
        <option value="D">D</option>
        <option value="E">E</option>
    </select>
    <input type="submit" value="Cus!">
</form>

然后将表单的值存储到$ code,我使用了一行脚本论坛

Then to store value of the form to $code, I used a line of script that I found in a forum

$code= empty ($_POST['code']) ? null : $_POST['code'];

实际上它有效,但没有解释。
任何人都可以向我解释一下吗?

Actually It worked, But it was not explained. Anybody can explain it to me??

推荐答案

这是三元。语法是 var =(true)? trueValue:falseValue; 它与此相同:

It's ternary. The syntax is var = (true) ? trueValue : falseValue; It's the same as this:

if  ( empty($_POST['code']) ) {
    $code =  null;
} else {
    $code = $_POST['code'];
}

这篇关于未定义的索引(PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆