PHP Program to Check for Upper Triangular Matrix Last Updated : 22 Jul, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a Square Matrix, the task is to check whether the matrix is in upper triangular form or not. A square matrix is called upper triangular matrix if all the entries below the main diagonal are zero. Examples: Input: mat = [ [1, 3, 5, 3], [0, 4, 6, 2], [0, 0, 2, 5], [0, 0, 0, 6]];Output: Matrix is in Upper Triangular formInput: mat = [ [5, 6, 3, 6], [0, 4, 6, 6], [1, 0, 8, 5], [0, 1, 0, 6]];Output: Matrix is not in Upper Triangular formHere is the complete PHP program to check if the matrix is in upper triangular form: PHP <?php // PHP Program to check for // upper triangular matrix $N = 4; // Function to check matrix is in // upper triangular form or not function isUpperTriangularMatrix($mat) { global $N; for ($i = 1; $i < $N; $i++) { for ($j = 0; $j < $i; $j++) { if ($mat[$i][$j] != 0) { return false; } }; } return true; } // Driver Code $mat = [ [1, 3, 5, 3], [0, 4, 6, 2], [0, 0, 2, 5], [0, 0, 0, 6] ]; if (isUpperTriangularMatrix($mat)) { echo "Yes"; } else { echo "No"; } ?> OutputYesTime Complexity: O(n2), where n represents the number of rows and columns of the matrix.Auxiliary Space: O(1), no extra space is required, so it is a constant.Please refer complete article on Program to check if matrix is upper triangular for more details! Comment More infoAdvertise with us Next Article How to Access and Print Matrix Element at Specific Position in PHP ? K kartik Follow Improve Article Tags : PHP Similar Reads PHP Program to Find the Maximum Element in a Matrix Given a matrix, the task is to find the maximum element of the matrix (arrays of arrays) in PHP. Finding the maximum element in a matrix is a common task that involves iterating through all the elements of the matrix and keeping track of the largest value found. Example: Input: matrix = [ [1, 2, 3], 4 min read How to Access and Print Matrix Element at Specific Position in PHP ? Accessing and printing elements at specific positions within a matrix is a fundamental operation in PHP when dealing with two-dimensional arrays. A matrix in PHP can be represented as an array of arrays, where each sub-array represents a row in the matrix. This article explores various approaches to 3 min read PHP | ImagickKernel fromMatrix() Function The ImagickKernel::fromMatrix() function is an inbuilt function in PHP which is used to create a kernel from an 2d matrix of values. The value of 2d matrix is either float if element is used otherwise false if element is skipped. Syntax: ImagickKernel ImagickKernel::fromMatrix( array $matrix, array 2 min read PHP | ctype_upper() Function The ctype_upper() function in PHP used to check each and every character of a given string is in uppercase or not. If the string in upper case then it returns TRUE otherwise returns False. Syntax: ctype_upper (string text) Parameter Used:- $text : The tested string. Return Value: Function returns Tr 2 min read PHP 7 | Spaceship Operator This article will make you aware of a very useful operator i.e the spaceship operator PHP 7. The spaceship operator or combined comparison operator is denoted by "". This is a three-way comparison operator and it can perform greater than, less than and equal comparison between two operands. This ope 2 min read PHP | ImagickKernel getMatrix() Function The ImagickKernel::getMatrix() function is an inbuilt function in PHP which is used to get the 2D matrix of values used in a kernel. The elements are either float or 'false' if element should be skipped. Syntax: array ImagickKernel::getMatrix( void ) Parameters:This function doesnât accepts any para 2 min read Like