การเขียนโปรแกรมเพื่อหาจำนวนแถว และหลัก ของสมาชิกในเมตริกซ์
[ PHP Code ]
<?php
$A = array(
array(1, 2, 1),
array(0, 1, 0),
array(2, 3, 4)
);
$B = array(
array(1, 2),
array(0, 1),
array(2, 3)
);
//So for Y (maxHeight)
$maxHeight = count( $A );
//And for X (maxWidth)
$maxWidth = max( array_map( 'count', $A ) );
echo "A = $maxHeight X $maxWidth";
$maxHeight = count( $B );
$maxWidth = max( array_map( 'count', $B ) );
echo "<br/>B = $maxHeight X $maxWidth";
?>
:: อ้างอิง ::
https://www.opendurian.com/learn/matrix_addition_and_multiplication/
http://php.net/manual/en/function.count.php
ความคิดเห็น
แสดงความคิดเห็น