answersLogoWhite

0

How do you define function in php?

Updated: 9/21/2023
User Avatar

Wiki User

12y ago

Best Answer

A function is defined in php by placing the keyword function before the chosen function name.

The function name must not match a pre-defined function and has certain limitation as to the characters that can be part of it. Notably, the function name must not contain any spaces. Following the function name are a parenthesis-enclosed, comma-separated list of variables, these variables are called calling parameters and are helpful if the function must process some values or follows diferent branches depending on external variables. Finally the function body is enclosed in curly brackets { }.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you define function in php?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you define a constant in PHP?

You can define a constant using the define() directive.you can use this a number of ways;to define a variable to a constant do:$string = "hello";define("string",$string);to define a string to a constant use:define("hello","there");to define a integer or other numerical value use:define("number",1.0);Summery:to define a string use quotes as you would do a string.Unlike variables in PHP a constant cannot be changed or undefined once it is defined. Constant remains automatically globally throughout the script. It means that it can be accessed from inside a function. e.g.


How does PHP function in applications?

in php used for one typ website


How do you use settime out in php?

we cant use set timeout function in php because it is of java script function


How do you return a value in a PHP function?

Below is a simple example of how you could return a value in a PHP function. <?php function returnme($value) { return $value; } echo returnme('hello'); // outputs: hello ?>


What is the way to create a function in PHP?

function function_name() { .................... }


What does the php function eval?

The eval() function evaluates a string as PHP code. http://us.php.net/manual/en/function.eval.php


How do you use a function with a button in PHP?

A simple function call <html> <body> <?php if(isset($_POST['button'])) { setValue(); // Function is called } function setValue() { echo "<br>The button property to call PHP function works"; // Your code here } ?> <input type="submit" name="button" onclick=<?php $_SERVER['PHP_SELF']; ?> /> </body> </head>


What is the purpose of function in PHP program?

The function keyword in PHP allows users to define functions beyond those built into the language, like so: function isFour ($number) { return $number == 4; }Functions in any language, including PHP, allow the developer to re-use their code. Without functions all of the code required to do the simplest of tasks must be re-written constantly; but with functions you must only write the code once and then call it whenever needed.


How do you change the current directory in PHP?

chdir() PHP function helps in changing the current directory.


What is the getopt function in PHP?

It gets options from the command line argument list. It can be used in PHP 4.3 and above, including PHP 5.


How do you find out the number of arguments passed to a function in PHP?

With a call to the function func_num_args().


What is header in php?

header() is a php function used to modify and set HTTP headers sent to the browser.