PHP ビンゴ_2 切り分け

index,php

-------

<?php

require_once(__DIR__ . '/config.php');
require_once(__DIR__ . '/Bingo.php');


$bingo = new \MyApp\Bingo();
$nums = $bingo->create();

?>

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charaset="utf-8">
<link rel="stylesheet" href="style.css">
</head>

<body>
<div id="container">
<table>
<tr>
<th>B</th><th>I</th><th>N</th><th>G</th><th>O</th>
</tr>
<?php for($i = 0; $i < 5; $i++): ?>
<tr>
<?php for($j = 0; $j < 5; $j++): ?>
<td><?= h($nums[$j][$i]); ?></td>
<?php endfor; ?>
</tr>
<?php endfor; ?>
</table>
</div>


</body>
</html>

-------

config.php

<?php

// エラー箇所がわかりやすくなる
ini_set('display_erros', 1);

require_once(__DIR__ . '/functions.php');

?>

-------

Bingo.php

<?php

namespace MyApp;

class Bingo {

public function create() {
$nums = [];

for ($i = 0; $i < 5;$i++) {
$col = range($i * 15 + 1,$i * 15 + 15);
shuffle($col);
$nums[$i] = array_slice($col, 0, 5);
}

$nums[2][2] = 'CENTER';
return $nums;
}

}

?>

--------

functions.php

<?php

function h($s) {
return htmlspecialchars($s,ENT_QUOTES,'UTF-8');
}

?>

-------

style.css

 

body {
font-family: Arial, sans-serif;
text-align: center;
font-size: 16px;
}

#container {
margin: 0 auto;
width: 100%;
}

table {
width: 100%;
height: 4em;
}

td, th {
width: 10%;
height: 3em;
}

th {
color: #F06292;
font-size: 22px;
}

td {
background: #F06292;
color: #fff;
}