我知道它要求太多时间。但isset
功能并没有解决我的问题。
$get = (isset($this->settings[$set['id']])) ? $this->settings[$set['id']] : '';
注意:未定义的索引:第419行的\ public_html \ settings.php中的id
也许,$set['id']
必须检查,像这样:
$set_ = isset($set['id']) ? $set['id'] : '';
$value = isset($this->settings[$set_]) ? $this->settings[$set['id']] : '';
在将变量用作参数之前,请尝试检查变量是否已设置。
$get = isset( $set['id']) ? $this->settings[$set['id']] : '';
我只是将它添加到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
时,如果你留下那个评论,那么输出是一个空字符串。