Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tasks-php
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Адлан Шамавов
tasks-php
Commits
ac3d64a9
Commit
ac3d64a9
authored
11 months ago
by
Адлан Шамавов
Browse files
Options
Downloads
Patches
Plain Diff
refactoring
parent
b98a6c79
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
add sortPrice
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
index.php
+8
-7
8 additions, 7 deletions
index.php
public/text.txt
+0
-2
0 additions, 2 deletions
public/text.txt
src/Functions.php
+25
-18
25 additions, 18 deletions
src/Functions.php
with
34 additions
and
27 deletions
.gitignore
0 → 100644
+
1
−
0
View file @
ac3d64a9
.vendor
\ No newline at end of file
This diff is collapsed.
Click to expand it.
index.php
+
8
−
7
View file @
ac3d64a9
<?php
require_once
__DIR__
.
'/vendor/autoload.php'
;
require_once
__DIR__
.
'/vendor/autoload.php'
;
$func
=
new
Hp\Test\Functions
()
;
use
Hp\Test\Functions
;
$func
=
new
Functions
();
?>
<!DOCTYPE html>
...
...
@@ -17,11 +18,11 @@ $func = new Hp\Test\Functions();
<h1>
Function 1
</h1>
<?php
$array
=
[
[
'price'
=>
10
,
'count'
=>
2
],
[
'price'
=>
5
,
'count'
=>
5
],
[
'price'
=>
8
,
'count'
=>
5
],
[
'price'
=>
12
,
'count'
=>
4
],
[
'price'
=>
8
,
'count'
=>
4
],
[
'price'
=>
10
,
'count'
=>
2
],
[
'price'
=>
5
,
'count'
=>
5
],
[
'price'
=>
8
,
'count'
=>
5
],
[
'price'
=>
12
,
'count'
=>
4
],
[
'price'
=>
8
,
'count'
=>
4
],
];
print_r
(
$func
->
sortPrice
(
$array
));
?>
...
...
This diff is collapsed.
Click to expand it.
public/text.txt
deleted
100644 → 0
+
0
−
2
View file @
b98a6c79
Раз, два, три, четыре,
Пять, шесть, семь, восемь.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/Functions.php
+
25
−
18
View file @
ac3d64a9
<?php
namespace
Hp\Test
;
declare
(
strict_types
=
1
)
;
use
DateTimeImmutable
;
use
DateTime
;
use
DateInterval
;
use
DatePeriod
;
namespace
Hp\Test
;
class
Functions
{
class
Functions
{
/**
* Выполняет сортировку массива по убыванию цены
*
* @param array $array
*
* @return array
*/
* Выполняет сортировку массива по убыванию цены
* @param array $array
* @return array
*/
function
sortPrice
(
array
$array
):
array
{
array_multisort
(
array_column
(
$array
,
'price'
),
SORT_DESC
,
array_column
(
$array
,
'count'
),
SORT_ASC
,
$array
);
public
function
sortPrice
(
array
$array
):
array
{
$prices
=
array_column
(
$array
,
'price'
);
$counts
=
array_column
(
$array
,
'count'
);
array_multisort
(
$prices
,
SORT_DESC
,
$counts
,
SORT_ASC
,
$array
);
return
$array
;
}
//На выход должна вернуть отсортированный массив по ключу *price* DESC и во вторую очередь по *count* ASC:
//[ ['price'=>12, 'count'=>4], ['price'=>10, 'count'=>2], ['price'=>8, 'count'=>4],
//['price'=>8, 'count'=>5], ['price'=>5, 'count'=>5], ]
}
/**
* На выход должна вернуть отсортированный массив по ключу *price* DESC
* и во вторую очередь по *count* ASC:
* [['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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment