1

After reading about the ... splat operator here: https://stackoverflow.com/a/56634367/429523

I decided to do this:

if (isset($some_array) && is_array($some_array)) {
    if (in_array($needle, array_merge(...$some_array), true)) {
        // do stuff...
    }
}

I'm receiving warnings like this:

PHP Warning: array_merge() expects at least 1 parameter, 0 given in...

PHP Warning: in_array() expects parameter 2 to be array, null given in...

How are these warnings getting past the isset / is_array if condition?

Leon
  • 1,478
  • 3
  • 16
  • 20
  • 1
    __Empty array__ (`array()` or `[]`) is __isset__ and is __array__. – u_mulder Jan 08 '20 at 17:44
  • 3
    use `if (!empty($some_array)` if that's what you actually mean; The answer to the asked question is you don't catch them – AD7six Jan 08 '20 at 17:46
  • You could use `array_merge([], ...$some_array)` to ensure that there's always at least 1 argument. – Barmar Jan 08 '20 at 17:51
  • 1
    @AD7six - yes, I believe that other question answers mine. Using !empty instead of isset resolved this for me. – Leon Jan 10 '20 at 14:06

0 Answers0