Function Examples

function GetLongDate ($MyDateTime)
{
  return date("l F jS Y", $MyDateTime);
}

//Using it
  echo GetLongDate (time());

Functions with optional arguments

function MyFunction ($MyArgA, $MyArgB = 22, $MyArgC = "My default value")
{

}

//Using it
  MyFunction(12);
  MyFunction(12, 13);
  MyFunction(12, 13, "Hello");
With a default array
function MyFunction ($MyArgA, $MyArgB = 
array() )
{

}

//Using it
  MyFunction(12);
  MyFunction(12, array(
    'comments' => 0,
    'responses' => 33
    )
  );



//Alternative way. and with a sub array added
  MyFunction(12);
  MyFunction(12, [
    'comments' => 0,
    'responses' => 33,
    'options' => ["min_range" => 18, "max_range" => 124]
    ]
  );
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *