Create an array containing the days of the week

You could simply code:

$days_of_week = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');

but thats the “noob” way, a real coder creates a function…

function days_of_week() {
	// declare days_of_week array
	$days_of_week = array();

	// get current date integer value (0 - 6)
	$day = date( "w" );

	// get current date values
	$today = date( "j" );
	$month = date( "n" );
	$year  = date( "Y" );

	// get start day and end day of the week
	$start_day = $today - $day;
	$end_day   = $start_day + 6;

	// build days of the week array
	for ( $i = $start_day; $i & lt;= $end_day; $i ++) {
		$days_of_week[] = date( "l", mktime( 0, 0, 1, $month, $i, $year ) );

	// return array
	return $days_of_week;

Update: 13/05/2018

Sigh What was wrong with me back then, this would have been so much better.

function days_of_week(){
	return = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');

Keep it simple, stupid!

Simple PHP increment function

Whenever I have to output a numbered list of data I usually run the following code to achieve the required result.

$counter = 0;
// for loop that does all the required code
// end for

but I have discovered a lovely little function that does all this for me.

function increment(&$counter){
return $counter

now I simply call


and it automatically outputs the next numeric.

Great! Simple and easy to use…..that’s the way to code.