From 2c821063c3c638ff48baafcd4fbff0530bc51bc9 Mon Sep 17 00:00:00 2001 From: Akex Date: Thu, 4 Apr 2024 11:03:54 +0500 Subject: [PATCH 1/2] first task done --- app/index.php | 10 ++++++++++ app/repository/SortPrice.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 app/repository/SortPrice.php diff --git a/app/index.php b/app/index.php index e69de29..c228b39 100644 --- a/app/index.php +++ b/app/index.php @@ -0,0 +1,10 @@ +10, 'count'=>2], ['price'=>5, 'count'=>5], ['price'=>8, 'count'=>5], ['price'=>12, 'count'=>4], ['price'=>8, 'count'=>4], ]; +$array = sortPrice($array); +var_dump($array); + + + + diff --git a/app/repository/SortPrice.php b/app/repository/SortPrice.php new file mode 100644 index 0000000..2b7a69d --- /dev/null +++ b/app/repository/SortPrice.php @@ -0,0 +1,31 @@ + $item){ + asort($item); + foreach ($item as $oneOfItem){ + $returnableArray[] = [ + [ + 'price'=>$key, + 'count'=>$oneOfItem + ] + ]; + } + } + + return $returnableArray; +} \ No newline at end of file -- GitLab From 19e7f6962ff5f239ef5b818b5d22aae397a20909 Mon Sep 17 00:00:00 2001 From: Akex Date: Thu, 4 Apr 2024 12:10:43 +0500 Subject: [PATCH 2/2] finish --- app/index.php | 6 +++--- app/repository/SlpitKeyValue.php | 19 +++++++++++++++++++ app/repository/SortPrice.php | 31 ------------------------------- app/repository/UniqElements.php | 25 +++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 34 deletions(-) create mode 100644 app/repository/SlpitKeyValue.php delete mode 100644 app/repository/SortPrice.php create mode 100644 app/repository/UniqElements.php diff --git a/app/index.php b/app/index.php index c228b39..4a38308 100644 --- a/app/index.php +++ b/app/index.php @@ -1,8 +1,8 @@ 10, 'count'=>2], ['price'=>5, 'count'=>5], ['price'=>8, 'count'=>5], ['price'=>12, 'count'=>4], ['price'=>8, 'count'=>4], ]; -$array = sortPrice($array); +$arr = [ ['laravel', 'php'], ['codeigniter', 'php'], ['laravel', 'php'], ['c++', 'java'], ]; +$array = uniqElements($arr); var_dump($array); diff --git a/app/repository/SlpitKeyValue.php b/app/repository/SlpitKeyValue.php new file mode 100644 index 0000000..738b5c2 --- /dev/null +++ b/app/repository/SlpitKeyValue.php @@ -0,0 +1,19 @@ + $item){ - asort($item); - foreach ($item as $oneOfItem){ - $returnableArray[] = [ - [ - 'price'=>$key, - 'count'=>$oneOfItem - ] - ]; - } - } - - return $returnableArray; -} \ No newline at end of file diff --git a/app/repository/UniqElements.php b/app/repository/UniqElements.php new file mode 100644 index 0000000..8966c71 --- /dev/null +++ b/app/repository/UniqElements.php @@ -0,0 +1,25 @@ + $item){ + $item = array_unique($item); + foreach ($item as $oneOfItem){ + $returnableArray[] = [ + [ + $key, + $oneOfItem + ] + ]; + } + } + + return $returnableArray; +} \ No newline at end of file -- GitLab