LoginSignup
1
0

More than 3 years have passed since last update.

PHPのisset()と等価な条件式を書いてisset()への理解を深めたい

Posted at

問い

$hoge を変数とする。 $hoge は定義されていて、かつ配列型であるとする。

このとき、 isset($hoge['fuga']['piyo']) と等価な条件式を書け。

ここで「2つの条件式が等価である」とは、「条件を満たすどのような $hoge に対しても2つの条件式の真偽が一致する」ことを意味することとする。

また、条件式を書くにあたっては論理演算子と以下の関数のみを用いることとする。

  • array_key_exists()
  • is_array
  • is_null

答えの例

array_key_exists('fuga', $hoge)
&& !is_null($hoge['fuga'])
&& is_array($hoge['fuga'])
&& array_key_exists('piyo', $hoge['fuga'])
&& !is_null($hoge['fuga']['piyo'])

証明

省略

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0