Commit 16c0b3e6 authored by Александр Плохих's avatar Александр Плохих 🌔
Browse files

Merge branch 'main' into 'PTPS|Function_4'

# Conflicts:
#   public/public/TestData/TestData.php
#   public/public/index.php
parents f0280eff 80161d05
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
<?php

namespace App\Actions;

class IdSearchAction
{
    /**
     * Найдет элемент с указаным id
     * @param array $array - массив, содержащий элементы со структурой
     * [
     * 'id' => 30,
     * 'name' => 'Jhon',
     * 'age' => 23,
     * ]
     * @param $id - ид искомого элемента
     * @return array|null - найденный элемент/ вернет null при его отсутствии
     */
    public static function search(array $array, $id): ?array
    {
        foreach ($array as $item){
            if ($item['id'] === $id){
                return $item;
            }
        }

        return null;
    }
}
+15 −0
Original line number Diff line number Diff line
@@ -66,4 +66,19 @@ class TestData
            'depth' => 1,
        ],
    ];

    public const ARRAY_FOR_SEARCHING = [
        [
            'id' => 30,
            'name' => 'Sasha',
        ],
        [
            'id' => 542,
            'name' => 'Adlan',
        ],
        [
            'id' => 3234,
            'name' => 'Pavel',
        ],
    ];
}
+8 −1
Original line number Diff line number Diff line
@@ -2,7 +2,14 @@

require_once __DIR__ . '/../vendor/autoload.php';

use App\Actions\IdSearchAction;
use App\Actions\PrepareMenuAction;
use App\TestData\TestData;

echo 'PrepareMenuAction: <br>';
var_dump(PrepareMenuAction::prepare(TestData::RAW_MENU));
echo '<hr>'

echo 'IdSearchAction: <br>'
var_dump(IdSearchAction::search(TestData::ARRAY_FOR_SEARCHING));
echo '<hr>'
 No newline at end of file