LoginSignup
1
0

More than 5 years have passed since last update.

配列の値をWEBページに表示する方法

Last updated at Posted at 2018-01-02

機能

配列の値をランダムに表示する

サンプルコード

index.php
<?php
function h($s) 
  return htmlspecialchars($s, ENT_QUOTES, 'UTF-8');
}

$QuizSet = [];
$QuizSet = [
  'q' => 'What is a ?',
  'a' => ['a1', 'a2', 'a3', 'a4']
];

shuffle($QuizSet['a']);
?>

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="utf-8">
  <title>Quiz</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  </ul>
    <?= $QuizSet['q'] ?>
    <?php foreach ($QuizSet['a'] as $a) : ?>
      <li><?= h($a) ?></li>
    <?php endforeach; ?>
  </ul>
</body>
</html>
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0