はじめに
PHPの超初心者向け書籍を購入し、初めて作ったプログラムを公開します。
rand関数を使って、おみくじプログラムを作ってみました。
おみくじプログラムの中身
Omikuji.php
<?php
$fortunes = array('大吉','中吉','小吉','末吉','凶');
$result = $fortunes[rand(0, count($fortunes)-1)];
echo "あなたの今日の運命は". $result . "です。". PHP_EOL;
発行するとランダムで、今日の運勢が出力されます。
試しに発行してみると、
$ php Omikuji.php
あなたの今日の運命は凶です。
凶でした。
以下使用している関数など
・array
配列
・rond
乱数を生成する
・PHP_EOL
改行コードを出力する