Follow Me
Subscribes Hell Buddy Solution.

Back To Top

Feel Glad finally done the Meta Tags generator and video :) project
- type: seo html - 30 September 2014 Tue @Hell Buddy

Home Message Share Translate

PHP function and date() add year Part 2

31October 2014

PHP function arguments with multiple parameters

function Something($argu1, $argu2...){
$var = $argu1 + $argu2;
$var2 = ....$argu3...$argu4...;
return 'Total is: $var and $var2';
echo Something('some', 'thing', '...'...);

Read the content or code / instruction -

How to add year automatically for each date variable through by function?

Continue: PHP function and date() add year Part 1, sometimes we will see the variables put into the function parentheses, so what is it? and how does it work?
The function parameter(s) is/are very useful and we will always use it to make a great program.

  1. date() and strtotime() functions

    $date = '01-01-2014'; // date string

    We are not only use on single current date time, also the others string. For example: membership renew by yearly, each member has name, specific date string as retrieve from the database.

    date('Y', strtotime('+12 month')); // e.g. format year and add 12 month or 1 year, output: 2021

  2. Less codes, more functions!

    Put the parameters into the function to passing the values or information and make the arguments to run out the function!

    renew($name, $date); // the parameters make function arguments

    We should not repeat the statement codes for each member if you got million memberships! More codes will have more chances to make mistakes. It's a time to make the programming work! As a real world example - when you put a slice bread and spread the peanut butter on, put it in an oven, and then it will toast the bread to you. Same idea here, the function set empty parameters, once you fill the variables in there that run the function, and then it's automatically make you a breakfast!

    function renew($name, $date){ echo ucwords($name).date('Y', strtotime('+12 month')); }

    // set up renew() function statement

    renew('someone name', '01-08-2020'); // echo out the function name with parameter put in


ucwords('someone name'); // output: Someone Name

renew('someone name','01-08-2020'); // Example function output: Someone Name 2021

Function is making the program becomes convenience and efficiency. Use ucwords() makes uppercase on each word of member's name. And the date string automatically add 1 year. You can re-use the function for many members in many times, and it echo out different renew date and member's name individually without making mistakes.

*** This is an important concept on PHP OOP (Object-Oriented Programming) system, very helpful for PHP programming enhancement in the future.

open the content >>

see the code OR slideshow instruction

//example on renew membership by yearly

//set the timezone first


//set the function arguments statement

function renew($name$date){
$join_day date('M-Y'strtotime($date));
$renew date('M-Y'strtotime($date.'+12 month'));
'From: '.$join_day.' to: '.$renew.'</p>';

//run out the function

renew('hell buddy''01-01-2014');
renew('jerky monk''01-08-2014');
renew('don don''10-10-2014');


Watch next videos and relative source page(s)

tag PHP - html
Programming Web Development Networking FunG project

Topic Discussion:

No Topic Discuss Now...
networking - computer & software