From 915b7ee27d758ad56e62450f712e53826bb81fe5 Mon Sep 17 00:00:00 2001 From: Akex Date: Thu, 4 Apr 2024 11:28:24 +0500 Subject: [PATCH 1/2] second task done --- app/index.php | 1 + app/repository/IdSearch.php | 1 + 2 files changed, 2 insertions(+) create mode 100644 app/index.php create mode 100644 app/repository/IdSearch.php diff --git a/app/index.php b/app/index.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/app/index.php @@ -0,0 +1 @@ + Date: Thu, 4 Apr 2024 11:35:51 +0500 Subject: [PATCH 2/2] second task done --- app/index.php | 19 +++++++++++++++++++ app/repository/IdSearch.php | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/app/index.php b/app/index.php index b3d9bbc..1331e48 100644 --- a/app/index.php +++ b/app/index.php @@ -1 +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 index b3d9bbc..9d1d818 100644 --- a/app/repository/IdSearch.php +++ b/app/repository/IdSearch.php @@ -1 +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 -- GitLab