diff --git a/app/index.php b/app/index.php new file mode 100644 index 0000000000000000000000000000000000000000..1331e48043e877ad5a188e472fbf904773ce2917 --- /dev/null +++ b/app/index.php @@ -0,0 +1,20 @@ +30, + 'name'=>'Sasha' + ], + [ + 'id'=>542, + 'name'=>'Adlan' + ], + [ + 'id'=>3234, + 'name'=>'Pavel' + ] +]; + +var_dump(search($array, 542)); diff --git a/app/repository/IdSearch.php b/app/repository/IdSearch.php new file mode 100644 index 0000000000000000000000000000000000000000..9d1d818cfed7e2067c6857d8ac0062479c00b80d --- /dev/null +++ b/app/repository/IdSearch.php @@ -0,0 +1,21 @@ + 30, + * 'name' => 'Jhon', + * 'age' => 23, + * ] + * @param $id - ид искомого элемента + * @return array - найденный элемент/ вернет null при его отсутствии*/ +function search($array, $id): ?array { + foreach ($array as $item){ + if ($item['id'] == $id){ + return $item; + } + } + return null; +} \ No newline at end of file