Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • a.plohih/stud-symfa
1 result
Show changes
Commits on Source (2)
<?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;
}
}
......@@ -8,5 +8,18 @@ namespace App\TestData;
class TestData
{
public const ARRAY_FOR_SEARCHING = [
[
'id' => 30,
'name' => 'Sasha',
],
[
'id' => 542,
'name' => 'Adlan',
],
[
'id' => 3234,
'name' => 'Pavel',
],
];
}
......@@ -2,6 +2,7 @@
require_once __DIR__ . '/../vendor/autoload.php';
use App\Actions /*placeholder for a class */;
use App\Actions\IdSearchAction;
use App\TestData\TestData;
var_dump(IdSearchAction::search(TestData::ARRAY_FOR_SEARCHING));