Function use in php

The real power of PHP comes from its functions; it has more than 1000 built-in functions.Click here to know about declared variable in php and as well as define array in php. Software Development Company in Delhi is offerings the different types of technical service and other services. 

PHP User Defined Functions

Besides the built-in PHP functions, we can create our own functions.

A function is a block of statements that can be used repeatedly in a program.

A function will not execute immediately when a page loads.

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

Create a User Defined Function in PHP

A user-defined function declaration starts with the word function:

Syntax

function functionName() {
    code to be executed;
}


Note: A function name can start with a letter or underscore (not a number).

Tip: Give the function a name that reflects what the function does!

Basics of Software Development your product may be a part of a web of Things (IoT) answer, includes massive information analysis, or ought to be integrated with alternative code systems

Function names are NOT case-sensitive.

In the example below, we create a function named "writeMsg()". The opening curly brace ( { ) indicates the beginning of the function code, and the closing curly brace ( } ) indicates the end of the function. The function outputs "Hello world!". To call the function, just write its name followed by brackets ():

Example

<?php
function writeMsg() {
    echo "Hello world!";
}

writeMsg(); // call the function
?>

PHP Function Arguments


Information can be passed to functions through arguments. An argument is just like a variable.

Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just separate them with a comma.

The following example has a function with one argument ($fname). When the familyName() function is called, we also pass along a name (e.g. Jani), and the name is used inside the function, which outputs several different first names, but an equal last name:

Example

<?php
function familyName($fname) {
    echo "$fname Refsnes.<br>";
}

familyName("Jani");
familyName("Hege");
familyName("Stale");
familyName("Kai Jim");
familyName("Borge");
?>

The following example has a function with two arguments ($fname and $year):

Example

<?php
function familyName($fname, $year) {
    echo "$fname Refsnes. Born in $year <br>";
}

familyName("Hege", "1975");
familyName("Stale", "1978");
familyName("Kai Jim", "1983");
?>

PHP Default Argument Value


The following example shows how to use a default parameter. If we call the function setHeight() without arguments it takes the default value as argument:

Example

<?php
function setHeight($minheight = 50) {
    echo "The height is : $minheight <br>";
}

setHeight(350);
setHeight(); // will use the default value of 50
setHeight(135);
setHeight(80);
?>

PHP Functions - Returning values


To let a function return a value, use the return statement:

Example

<?php
function sum($x, $y) {
    $z = $x + $y;
    return $z;
}

echo "5 + 10 = " . sum(5, 10) . "<br>";
echo "7 + 13 = " . sum(7, 13) . "<br>";
echo "2 + 4 = " . sum(2, 4);
?>
Faridabad Ford | Best Ford Showroom and Dealership in Faridabad

Welcome to Faridabad Ford, the largest & best ford showroom and dealership in Faridabad, your Biggest Ford Dealer for New and Used Car Sales, Servicing, Parts and Accessories.

Ghaziabad Ford | Best Ford Showroom and Dealership in Ghaziabad

Welcome to Ghaziabad Ford, the largest & best ford showroom and dealership in Ghaziabad, your Biggest Ford Dealer for New and Used Car Sales, Servicing, Parts and Accessories. We can help make your process of Buying, Servicing or Selling your car a lot easier.

List of Backlinks
http://www.faridabadford.com/
http://www.ghaziabadford.com/

List of Back links

https://www.reddit.com/user/Delhifordsafdarjung

https://www.tumblr.com/blog/delhifordsafdarjung

https://in.pinterest.com/pin/800374165009824439/

https://mix.com/delhifordsafdarjung

https://www.scoop.it/u/delhifordsafdarjung
https://www.myvidster.com/profile/Delhiford

https://www.mightycause.com/user/sy7e4f/preview

https://ello.co/delhiford

https://www.viki.com/users/delhiford/about

https://worldcosplay.net/member/824006

http://forums.skydemon.aero/UserInfo15670.aspx

https://publiclab.org/profile/Delhiford

https://www.reverbnation.com/delhiford?profile_view_source=header_icon_nav

https://id.arduino.cc/

https://www.fanfiction.net/~metrochevrolet

https://www.fodors.com/community/profile/delhiford/about-me

https://flattr.com/@MetroChevrolt

https://www.spreaker.com/user/11449942

https://ello.co/metrochevrolet

https://flattr.com/@MetroChevrolt

https://www.myvidster.com/profile/Metrochevrolet#prettyPhoto

https://www.indiegogo.com/individuals/22172342

http://songvault.fm/

http://bbs.vernee.cc/home.php?mod=space&uid=916270

https://www.informationweek.com/profile.asp

http://forum.yealink.com/forum/member.php?action=profile&uid=90451

https://onmogul.com/tricityford

http://www.effecthub.com/user/1672019

http://metalstorm.net/users/Tricityford/profile



Comments

Popular posts from this blog

How Outsourced Healthcare Services Leads to Improved Patient Experience?

BS6 compliant Ford EcoSport launched in India, price starts at Rs 8.04 lakhs

Best DoFollow profile creation sites list OCT 2019