0

I know it asks too many time. But the isset function is not solve my problem.

$get = (isset($this->settings[$set['id']])) ? $this->settings[$set['id']] : '';

Notice: Undefined index: id in \public_html\settings.php on line 419

Habip Oğuz
  • 921
  • 5
  • 17
Paul Green
  • 142
  • 8

3 Answers3

2

Try to check if the variable is set before using it as an argument.

$get = isset( $set['id']) ? $this->settings[$set['id']] : '';
Vidal
  • 2,605
  • 2
  • 16
  • 32
1

Maybe, $set['id'] must check, like this:

$set_ = isset($set['id']) ? $set['id'] : '';
$value = isset($this->settings[$set_]) ? $this->settings[$set['id']] : '';
Habip Oğuz
  • 921
  • 5
  • 17
1

I would simply add it to the isset call

$get = isset( $set['id'],$this->settings[$set['id']]) ? $this->settings[$set['id']] : '';

You can use multiple arguments in isset. This is roughly equivalent to doing this:

$get = isset($set['id']) && isset($this->settings[$set['id']]) ? $this->settings[$set['id']] : '';

This can be easily tested with this code:

$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;

When $set = ['id' => 'foo'] the output is bar if you leave that commented then the output is an empty string.

Sandbox

ArtisticPhoenix
  • 21,464
  • 2
  • 24
  • 38