Skip to main content

PHP functions

A function is a block of code that can be executed whenever required. A function will be executed by a call to the function.
You may call a function from anywhere within a page. Give the function a name that reflects what the function does. The function name can start with a letter or underscore but not a number.
Syntax
function functionName()
{
code to be executed
}
Creating a simple function
<?php
function hello(){
echo “This is my first simple function”;
}
//call php function
hello();
?>

PHP function with parameters
<?php
function myHello($firstname)
{
echo “Namaste “. $firstName . “!<br />”;
}
//call function
myHello(“Ram”);
?>
Display:
Namaste Ram !
Another example
<?php
function addNumber($num1, $num2)
{
$num3= $num1+$num2;
echo “The sum is”.$num3;
}
//function call
addNumber(15,25);
?>

Comments

Popular posts from this blog

CSS List

CSS allows you to customize the lists that can be made with HTML  to the extent that even images can be used as bullet points for unordered lists. CSS List Style Type If you want to use something different from the default numbering of ordered lists, or the bullets/discs of unordered lists, then all you have to do is choose a different style for your lists. CSS allows you to select from a wide variety of different list item shapes. Unordered list styles: square, circle, disc (default), and none Ordered list styles: upper-alpha, lower-alpha, upper-roman, lower-roman, decimal (default), and none Code:

Accessible Forms

Forms aren't the easiest of things to use for people with disabilities. Navigating around a page with written content is one thing, hopping between form fields and inputting information is another. Because of this, it is a good idea to add a number of elements to the form. Labels Each form field should have its own label. The label tag sorts this out, with a for attribute that associates it to a form element:

Join in MySQL

Join clause is used to combine rows from two or more tables depending upon common field between them. There are different kinds of Joins. The most common and useful Join is Inner Join. Inner Join: It will return all rows from multiple tables where the condition is met.