mar*_*ila 3 php variables undefined defined
我form[fieldsdata]
只喜欢使用已定义的内容:
$fieldsJson = $data["form[fieldsdata]"] ? $data["form[fieldsdata]"] : "";
Run Code Online (Sandbox Code Playgroud)
但是错误消息仍然是:
注意:未定义的索引:form [fieldsdata]
您可以使用isset()
检查是否已定义它,或者(如果使用的是PHP 7)使用空合并运算符(??)。
$fieldsJson = isset($data["form[fieldsdata]"]) ? $data["form[fieldsdata]"] : "";
Run Code Online (Sandbox Code Playgroud)
$fieldsJson = $data["form[fieldsdata]"] ?? "";
Run Code Online (Sandbox Code Playgroud)
请注意,如果索引存在但具有null
值,则使用空合并也将应用空字符串值。