Commit bc646cb7 authored by Nikita Chernykh's avatar Nikita Chernykh
Browse files

Merge branch 'PTPS_Function_2' into 'main'

Ptps function 2

See merge request !2
parents 5b335147 bf8ad095
Loading
Loading
Loading
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"
}
+11 −0
Original line number Diff line number Diff line
@@ -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
+23 −1
Original line number Diff line number Diff line
@@ -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;
    }
}