function isRowSorted($matrix, $row) {
$cols = count($matrix[0]);
for ($i = 1; $i < $cols; $i++) {
if ($matrix[$row][$i - 1] > $matrix[$row][$i]) {
return false;
}
}
return true;
}
$matrix = array(
array( 4, 7, 9, 12),
array( 1, 8, 3, 4),
array(-9, -4, -3, 2),
array(-8, -3, -9, 4),
array( 2, 6, 7, 18)
);
echo "Row 0: " . isRowSorted($matrix, 0) . "\n";
echo "Row 1: " . isRowSorted($matrix, 1) . "\n";
echo "Row 2: " . isRowSorted($matrix, 2) . "\n";
echo "Row 3: " . isRowSorted($matrix, 3) . "\n";
echo "Row 4: " . isRowSorted($matrix, 4) . "\n";
/*
run:
Row 0: 1
Row 1:
Row 2: 1
Row 3:
Row 4: 1
*/