The characteristic of the row of an integer matrix is the sum of its positive even elements. Rearranging the rows of a given matrix, arrange them in accordance with the growth characteristics.
function SortMatrixBySumOfRows($matrix) { // Этап 1. Ищу базовую сумму - сумма элементов первой строки $sum = 0; for($j = 0; $j < count($matrix[0]); $j++) $sum += $matrix[0][$j]; // Этап 2. Сортировка по сумме строк $temp = 0; for($i = 0; $i < count($matrix); $i++) { for ($j = 0; $j < count($matrix[$i]); $j++) { if($matrix[$i][$j] >= 0 && $matrix[$i][$j] % 2 == 0) $temp += $matrix[$i][$j]; } if($temp > $sum) { for ($k = 0; $k < n; $k++){ $buf = $matrix[$j][$k]; $matrix[$j][$k] = $matrix[$j+1][$k]; $matrix[$j+1][$k] = $buf; } $sum = $temp; } } } People, help me deal with stage 2. It seemed that already having the amount you can already do an easy sorting, but you need to write another cycle that changes the elements. Where did you screw up?