Web Design

(Nancy Kaufman) #1

290


Create Your Own PHP Function ................................


3 Type function ?(), replacing
? with a name for the
function.
4 Type {.
5 Type the code you want to
have the function execute.
6 Type }.
7 Type ?>.

1 In your editor, open an
existing PHP document or
create a new one.
2 At the top of the page, type
<?php.

Create Your Own PHP Function


Y


ou can encapsulate PHP code that you need to reuse into functions. The syntax for creating PHP
functions is nearly identical to that for creating functions in JavaScript: You begin by using the

function keyword, followed by the name of the function and a pair of parentheses. The code


for the function is enclosed in curly braces. You can pass arguments to the function by creating


variables within the parentheses, and send a value out of the function using the return keyword.


Functions are called in PHP by simply referencing their name.


1


2


3


5


7


4


6

Free download pdf