descendingOrder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
Your task is to make a function that can take any non-negative integer as a argument and return it with its digits in descending order. Essentially, rearrange the digits to create the highest possible number.
4
Examples:
5
6
Input: 21445 Output: 54421
7
8
Input: 145263 Output: 654321
9
10
Input: 1254859723 Output: 9875543221
11
*/
12
13
/**
14
 * descendingOrder
15
 *
16
 * @param  int $number
17
 * @return int
18
 */
19
function descendingOrder(int $number): int
20
{
21
  $number = (int)$number;
22
  $arrayNumber = str_split($number);
23
24
  $arrayNumber = (array)$arrayNumber;
25
  arsort($arrayNumber);
26
27
  return (int)implode($arrayNumber);
28
}
29