Tuesday, January 28, 2014

PHP Functions


To keep the script from being executed when the page loads, you can put it into a function.
A function will be executed by a call to the function. You may call a function from anywhere within a page.

Create a PHP Function

A function will be executed by a call to the function.

Syntax

function functionName()
{
code to be executed;
}
PHP function guidelines:
  • Give the function a name that reflects what the function does
  • The function name can start with a letter or underscore (not a number)

PHP Functions - Adding parameters

To add more functionality to a function, we can add parameters. A parameter is just like a variable.
Parameters are specified after the function name, inside the parentheses.
bl.�reP�$�#pacing=0 cellpadding=0 style='margin-left:-1.75pt;border-collapse:collapse;mso-table-layout-alt:fixed; mso-padding-alt:2.0pt 2.0pt 2.0pt 2.0pt'>
foreach ($array as $value)
  {
  code to be executed;
  }

For every loop iteration, the value of the current array element is assigned to $value (and the array pointer is moved by one) - so on the next loop iteration, you'll be looking at the next array value.

No comments:

Post a Comment