• Home
  • Swinburne University of Technology
  • Computing Technology Inquiry Project
  • PHP Functions and Form Data Processing

PHP Functions and Form Data Processing

SWIN BUR NE SWINBURNE UNIVERSITY OF TECHNOLOGY COS10026 Computing Technology Inquiry Project Lecture 8 PHP 2 - Functions and Form Data Processing Topics · Functions and Scope · Control Flow · Form Data Processing SWINBURNE UNIVERSITY OF TECHNOLOGY SWIN BUR * NE * Defining Functions · Functions are groups of statements that you can execute as a single unit · Function definitions are the lines of code that make up a function · Syntax for defining a function is: <? php function nameOfFunction (parameters) statements; { } ?> Functions http://php.net/manual/en/language.functions.php Defining Functions (continued) SWIN BUR SWINBURNE UNIVERSITY OF TECHNOLOGY * NE * . PHP Functions must be contained within <? php ?> tags · A parameter is a variable that is used within a function . Parameters are placed within the parentheses that follow the function name · Functions do not have to contain parameters . The set of curly braces (called function braces) contain the function statements SWINBURNE UNIVERSITY OF TECHNOLOGY SWIN BUR * NE * Defining Functions (continued) · Function statements do the actual work of the function and must be contained within the function braces function printNames ($name1, $name2, $name3) { echo "<p>$name1</p>"; echo "<p>$name2</p>"; echo "<p>$name3</p>"; } Calling Functions SWIN BUR * NE * SWINBURNE UNIVERSITY OF TECHNOLOGY Formal Parameter Function definition Function invocation function printCompanyName ($companyName) { echo "<p>$companyName</p>"; Actual Parameter } printCompanyName ( "Web App Creators") ; File Edit View History Bookmarks Tools Help PHP Function Demo × + /L9_basics.php Q Search » Web App Creators X 0 = Output of a call to a custom function SWIN BUR * NE * SWINBURNE UNIVERSITY OF TECHNOLOGY