我知道它问了太多时间。但是isset
函数不能解决我的问题。
$get = (isset($this->settings[$set['id']])) ? $this->settings[$set['id']] : '';
注意:未定义索引:第419行的\ public_html \ settings.php中的ID
答案 0 :(得分:2)
在将变量用作参数之前,请尝试检查该变量是否已设置。
$get = isset( $set['id']) ? $this->settings[$set['id']] : '';
答案 1 :(得分:1)
也许[data-v-f3f3eg9] .my-icon {
background: red;
}
必须像这样检查:
$set['id']
答案 2 :(得分:1)
我只需将其添加到isset调用中
$get = isset( $set['id'],$this->settings[$set['id']]) ? $this->settings[$set['id']] : '';
您可以在isset中使用多个参数。这大致等同于执行此操作:
$get = isset($set['id']) && isset($this->settings[$set['id']]) ? $this->settings[$set['id']] : '';
可以使用以下代码轻松对其进行测试:
$array = ['foo' => 'bar'];
$set = []; //not set
#$set = ['id' => 'foo']; //uncomment to test if set
#using [] to add an element to a string not an array
$get = isset($set['id'],$array[$set['id']]) ? $array[$set['id']] : '';
echo $get;
当$set = ['id' => 'foo']
输出为bar
时,如果您保留该注释,则输出为空字符串。