How to print the corners of a matrix in PHP

1 Answer

0 votes
function printMatrixCorners($matrix) {
    echo "left top corner: " . $matrix[0][0] . "\n";
    echo "right top corner: " . $matrix[0][count($matrix[0]) - 1] . "\n";
    echo "left bottom corner: " . $matrix[count($matrix) - 1][0] . "\n";
    echo "right bottom corner: " . $matrix[count($matrix) - 1][count($matrix[0]) - 1] . "\n";
}

$matrix = array(
    array(1, 2, 3, 4),
    array(5, 6, 7, 8),
    array(9, 3, 2, 0)
);

printMatrixCorners($matrix);



/*
run:

left top corner: 1
right top corner: 4
left bottom corner: 9
right bottom corner: 0

*/

 



answered May 20, 2024 by avibootz

Related questions

1 answer 118 views
118 views asked May 20, 2024 by avibootz
1 answer 152 views
1 answer 161 views
1 answer 94 views
94 views asked May 20, 2024 by avibootz
1 answer 98 views
1 answer 100 views
1 answer 81 views
...