S
S
Sergey Korenevsky2022-03-23 01:38:11
PHP
Sergey Korenevsky, 2022-03-23 01:38:11

How to check if a nested key exists in an array in PHP?

I have a class with an EXIST() method

class X{
  private $data = ['a'=>['b'=>123], 1 => []];

  public function exists($name)	{
    return isset($this->data[$name]);
  }
}

The $this->data array is deeply nested. Is it possible to somehow pass the name of the key to the method, taking into account the nesting of the entire chain, and get the check for the presence of the key ?
$this->data = ['a'=>['b'=>123], 1 => []]
'b'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2022-03-23
@SilenceOfWinter

need to find b in any nested array (leaves or branches) or specifically in leaves?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question