Основной PHP - как использовать несколько функций? - PullRequest
0 голосов
/ 01 сентября 2018

Я учусь использовать несколько функций PHP. но почему он получает ошибку?

это мой код PHP:

//sorting the number from small to big
function sorting($arrNumber) {
  $unsortedArray = $arrNumber;
  for ($i = 0; $i < count($unsortedArray); $i++) {
    for ($j = $i + 1; $j < count($unsortedArray); $j++) {
      if ($unsortedArray[$i] < $unsortedArray[$j]) {
        $a = $unsortedArray[$j];
        $unsortedArray[i] = $unsortedArray[j];
        $unsortedArray[j] = $a;
      }
    }
  }
  return $unsortedArray;
}

//getting total of how many time the biggest number appear
function getTotal($arrNumber) {
  $biggestNumber = $arrNumber[count($arrNumber) - 1];
  $totalBiggestNumber = 0;
  for ($i = 0; $i < count($arrNumber); $i++) {
    if ($arrNumber[$i] == $biggestNumber) {
      $totalBiggestNumber += 1;
    }
  }
  return $totalBiggestNumber;
}

//returning the value
function mostFrequentLargestNumbers($arrNumber) {
  $listSort = sorting($arrNumber);
  $countHighest = getTotal($listSort);
  return 'the biggest number is ' . $listSort[count($listSort) - 1] . ', appearing ' . $countHighest . ' times.'
}

mostFrequentLargestNumbers(array(2, 8, 4, 6, 8, 5, 8, 4));
// this should return 'the biggest number is 8 and appearing 3 times'

mostFrequentLargestNumbers(array(122, 122, 130, 100, 135, 100, 135, 150));
// this should return 'the biggest number is 150 and appearing 1 times'

mostFrequentLargestNumbers(array(1, 1, 1, 1));
// this should return 'the biggest number is 1 and appearing 4 times'

так что это все моя функция. почему я получаю ошибку? что-то не так с моим кодом?

1 Ответ

0 голосов
/ 01 сентября 2018

Вам не хватает точки с запятой для завершения оператора в следующей строке (третья функция):

return 'the biggest number is ' . $listSort[count($listSort) - 1] . ', appearing ' . $countHighest . ' times.'
...