Tag: function

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 <= $end_day; $i++) {
$days_of_week[] = date(“l”, mktime(0,0,1,$month,$i,$year));

// return array
return $days_of_week;

Filed under: DevelopmentTagged with: , ,

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.

Filed under: DevelopmentTagged with: ,