6:21 am

Create a PHP Function
Syntax
- function functionName()
- {
- code to be executed;
- }
- Give the function a name that reflects what the function does
- The function name can start with a letter or underscore (not a number)
Example
- A simple function that writes my name when it is called:
- <html>
- <body>
- <?php
- function writeName()
- {
- echo "MONA";
- }
- echo "My name is "; writeName();
- ?>
- </body>
- </html>
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.
Example 1
- The following example will write different first names, but equal last name:
- <html>
- <body>
- <?php
- function writeName($fname)
- {
- echo $fname . " BRT.<br />";
- }
- echo "My name is "; writeName("MONA");
- echo "My sister's name is "; writeName("Hege");
- echo "My brother's name is "; writeName("Stale");
- ?>
- </body>
- </html>
- Output:
- My name is MONA BRT
PHP Functions - Return values
- To let a function return a value, use the return statement.
Example
- <html>
- <body>
- <?php function add($x,$y)
- {
- $total=$x+$y; return $total;
- }
- echo "1 + 16 = " . add(1,16);
- ?>
- </body>
- </html>
Yoou can also uncover other printtable coupon settings bby
ReplyDeletecarrying out a rapid look for them in your preferred internet search engine.
Here is my blog - kohls promo codes, cityinsider.com,