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.shamavov/tasks-php
1 result
Show changes
Commits on Source (8)
{
"_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;
}
}