PHP: Flip a coin

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

	.coin {
		background: #e2e2e2;
		color: #333333;
		border-radius: 50%;
		padding: 50px;
		text-align: center;
		font-size: 2rem;
		font-weight: bold;
		width: 50px;

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

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

Random outcome will be on page refresh as following.

Functional example:

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