Loading composer.lock 0 → 100644 +18 −0 Original line number Diff line number Diff line { "_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" } index.php +11 −0 Original line number Diff line number Diff line Loading @@ -26,5 +26,16 @@ ]; print_r($func->sortPrice($array)); ?> <h1>Function 2</h1> <?php $array = [ ['id'=>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)); ?> </body> </html> No newline at end of file src/Functions.php +23 −1 Original line number Diff line number Diff line Loading @@ -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],] */ /** * Найдет элемент с указаным 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; } } Loading
composer.lock 0 → 100644 +18 −0 Original line number Diff line number Diff line { "_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" }
index.php +11 −0 Original line number Diff line number Diff line Loading @@ -26,5 +26,16 @@ ]; print_r($func->sortPrice($array)); ?> <h1>Function 2</h1> <?php $array = [ ['id'=>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)); ?> </body> </html> No newline at end of file
src/Functions.php +23 −1 Original line number Diff line number Diff line Loading @@ -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],] */ /** * Найдет элемент с указаным 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; } }