私は数時間のような時間を探していますが、解決策は見当たりません。 パスカル三角形をテーブルに表示したいときに問題がありますが、実際には正しく表示されません。 ここでは、コードです: `PHP Pascalの三角形がテーブルに正しく表示されない
<!DOCTYPE html>
<html>
<head>
<title>Triangle de Pascal</title>
<meta charset="utf-8">
</head>
<body>
<form action="index.php" method="POST">
<label for="depth">Profondeur : </label>
<input type="number" id="depth" name="depth" min="1" max="100">
<input type="submit">
</form>
<style>
table{
border-collapse: collapse;
}
td{
text-align: center;
padding: 0px 5px; border: 1px solid black;
box-sizing: border-box;
}
</style>
<table>
<?php
$depth = $_POST['depth'];
$length = $depth;
$array[0][0] = 1;
for ($i = 1; $i < $depth; $i++){
$array[$i][0] = 1;
echo "<tr>";
for($j = 1; $j <= $i; $j++){
if($j == $i){
$array[$i][$j] = 1;
}
else{
$array[$i][$j] = $array[$i-1][$j-1] + $array[$i-1][$j];
}
echo "<td colspan=".floor($length * $length/($i)).'>'.$array[$i][$j]."</td>";
}
echo "</tr>";
}
?>
</table>
</body>
</html>
あなたは、ループ内の論理エラーを持っている問題
出力として何を期待していますか? – pr1nc3