Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
1 merge request!2Ptps function 2
{
"_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"
}
......@@ -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
......@@ -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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment