diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000000000000000000000000000000000000..d2b7326968b5c9c73bc71201c5f02bb6444bfed8 --- /dev/null +++ b/composer.lock @@ -0,0 +1,18 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "fb868aee4271b4f211fa6443b05e3b80", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.6.0" +} diff --git a/index.php b/index.php index 651ccfbea744d87d99de366bba48dcd93c23c471..ff183a17bf13acfa9673cbc193be270e7a109a53 100644 --- a/index.php +++ b/index.php @@ -26,5 +26,16 @@ ]; print_r($func->sortPrice($array)); ?> + +

Function 2

+ 10, 'name'=>'Jhon', 'age'=>23], + ['id'=>32, 'name'=>'Alex', 'age'=>34], + ['id'=>54, 'name'=>'Bob', 'age'=>45], + ['id'=>6, 'name'=>'Mike', 'age'=>61], + ]; + print_r($func->search($array, 54)); + ?> \ No newline at end of file diff --git a/src/Functions.php b/src/Functions.php index fcc660fee8ea83a97c8fa655711caf9b9784f3f6..2c2ad2af35a9d442745830bd8ef129c2646f6bed 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -31,4 +31,26 @@ class Functions * [['price'=>12, 'count'=>4], ['price'=>10, 'count'=>2], ['price'=>8, 'count'=>4], * ['price'=>8, 'count'=>5], ['price'=>5, 'count'=>5],] */ -} \ No newline at end of file + + /** + * Найдет элемент с указаным id + * @param array $array - массив, содержащий элементы со структурой + * [ + * 'id' => 30, + * 'name' => 'Jhon', + * 'age' => 23, + * ] + * @param $id - ид искомого элемента + * @return ?array - найденный элемент + */ + + public function search(array $array, int $id): ?array + { + $rowId = array_search($id, array_column($array, 'id'), true); + if ($rowId) { + return $array[$rowId]; + } + return null; + } +} +