PHP: Flip a coin

In this post, we will write a small program that will flip a coin for us. Let’s start

<style>
	.coin {
		background: #e2e2e2;
		color: #333333;
		border-radius: 50%;
		padding: 50px;
		text-align: center;
		font-size: 2rem;
		font-weight: bold;
		width: 50px;
	}
</style>
<?php

function flip() {
	return 0 == rand(0,1) ? 'Head' : 'Tail';

?>
<div class="coin">
	<?php echo flip(); ?>
</div>

Random outcome will be on page refresh as following.

Functional example:
https://code.danyal.dk/php/flip-coin.php

Author: Danyal
I'm working as programmer since 2002. Born, grew up, studied and worked in Pakistan now Im located in Denmark since 2006.