0% found this document useful (0 votes)
23 views

03MAY

A function in PHP is a reusable block of code that performs a specific task. It takes input parameters, performs actions, and returns an output value. There are built-in functions included with PHP like echo, gettype(), and var_dump() that can be called directly to perform tasks without being defined. Functions allow code reusability, less code by writing logic once, and easier program understanding by separating logic into blocks.

Uploaded by

dollar content
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

03MAY

A function in PHP is a reusable block of code that performs a specific task. It takes input parameters, performs actions, and returns an output value. There are built-in functions included with PHP like echo, gettype(), and var_dump() that can be called directly to perform tasks without being defined. Functions allow code reusability, less code by writing logic once, and easier program understanding by separating logic into blocks.

Uploaded by

dollar content
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Test 1 - Improve the content of the “Working with Functions in PHP” topic.

Note:
 You should read and understand the content and then rewrite it. Do this
rewriting in the same document with track changes on.
 No similarity should be found. The representation of content should also be
different from the original.
 Ensure that the document you send is plagiarism-free. So, rewrite such that
no three consecutive words in a sentence match with the original.

----------------------------------------------------------

Working with Functions in PHP

PHP Functions

PHP function is a piece of code that can be reused many times. It can take input as argument list
and return value. There are thousands of built-in functions in PHP.

In php function is a block of statements that can be repeatedly used/executed in a code to perform
specific action.

It takes one or more inputs as a parameter and processes it and returns a value.

It takes one or more inputs as a parameter/argument list, processes it and returns a value.

Functions can be defined as following in PHP


Conditional Function
Nested functions (Aka: functions inside functions)
Recursive function 

Built in Functions:
PHP has over thousands of built-in functions that perform different tasks.

PHP comes standard with huge collection of built-in functions. To use these functions .You can call
these functions, from within a script, to execute or repeat specific tasks. Some of the examples are
exit()
file_get_contents()
file_put_contents()
include()
preg_match()
print_r()
rand()
str_replace()
str_len()

https://quickdraft.pro Sample Test Page 1 of 7


. They give us an easier way to implement and repeat popular tasks throughout a program. A
popular example is the echo function.

huge collection of built-in library functions. These functions are already coded and stored
in form of functions. To use those we just need to call them as per our requirement like,
var_dump, fopen(), print_r(), gettype() and so on.

echo "I am built in";


In addition to a description of what the function does, the documentation for each function
denotes:

Documentation of function

 The name of the function


 Required parameters and their types
 Optional parameters (in square brackets, []), their types, and default values
 The return type of the function (after the final colon, :)

 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 ():

 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:

 The name of the function


 Required parameters and their types
 Optional parameters (in square brackets, []), their types, and default values
 The return type of the function (after the final colon, :)

echo "I am built in";

https://quickdraft.pro Sample Test Page 2 of 7


PHP comes with a number of built-in functions. These functions—also known as internal functions
— can be invoked without writing them ourselves. In this lesson, we’ll explore some useful built-in
functions and empower you to discover new built-in functions yourself.
PHP includes useful built-in functions for getting information about
variables. The gettype() function takes a variable as its argument and returns a string value
representing the data type of the argument.
$name = "Aisle Nevertell";
$age = 1000000;

echo gettype($name); // Prints: string

echo gettype($age); // Prints: integer


Notice that we didn’t write a definition for the gettype() function ourselves—it’s built into PHP.
Since the function is included within the language itself, we can just call it anywhere within our PHP
code.
Let’s take a look at another built-in function! The var_dump() function also takes a variable
argument. It prints details about the argument it receives.
var_dump($name); // Prints: string(15) "Aisle Nevertell"

var_dump($age); // Prints: int(1000000)


In the code above, we first used var_dump() to print information about the variable $name. string(15)
—the variable’s type and length—were printed followed by the value held by the variable.
Next, we used var_dump() to print information about the variable $age. Here, the integer is printed
within the parentheses.
PHP has over 1000 built-in functions that can be called directly, from within a script, to perform a
specific task.

IN PHP, many functions are used such as built-in functions and user-defined functions. Each
and every function has its own functionality and properties. A

It takes input from the user in the form of parameters, performs certain actions, and gives the
output. Functions can either return values when called or can simply perform an operation
without returning any value.

It is a piece of code that takes one or more inputs as a


parameter and processes it and returns a value.
. It takes input from the user in the form of parameters,
performs certain actions, and gives the output. Functions
can either return values when called or can simply
perform an operation without returning any value.

https://quickdraft.pro Sample Test Page 3 of 7


It takes input

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


 A function will not execute automatically when a page loads.
 A function will be executed by a call to the function.

 Function in PHP is a reusable piece or block of code


that performs a specific action. It takes input from the
user in the form of parameters, performs certain actions,
and gives the output. Functions can either return values
when called or can simply perform an operation without
returning any value.

In PHP, we can define Conditional function, Function within Function and Recursive function also.

A function in PHP is a self-contained block of code that


use to performs a specific task in the program. In
another word, we can say that PHP function is a piece of
code that can be reused many times in a PHP based web
application.
There are two types of function. One is the built-in or
internal functions that already in PHP and you can use
it. The other one is user defined function that can be
defined by users for a task.
 
 Function in PHP is a reusable piece or block of code
that performs a specific action. It takes input from the
user in the form of parameters, performs certain actions,
https://quickdraft.pro Sample Test Page 4 of 7
and gives the output. Functions can either return values
when called or can simply perform an operation without
returning any value.
PHP has over 700 functions built in that perform
different tasks.
IN PHP, many functions are used such as built-in
functions and user-defined functions. Each and every
function has its own functionality and properties. A
function is a set of statements written in the program
that can be used multiple times in the code anywhere
needed. A function call is required to execute the
statements written inside the function. It is a piece of
code that takes one or more inputs as a parameter and
processes it and returns a value. Programmers simply
have to create a function and then call that function in
the program wherever required.
 

Advantage of PHP Functions

Code Reusability: PHP functions are defined only once and can be invoked many times, like in other
programming languages.

Less Code: It saves a lot of code because you don't need to write the logic many times. By the use
of function, you can write the logic only once and reuse it.

Easy to understand: PHP functions separate the programming logic. So it is easier to understand
the flow of the application because every logic is divided in the form of functions.

7.1 PHP Built-in Functions

PHP comes standard with many built-in functions. They give us an easier way to implement and
repeat popular tasks throughout a program. A popular example is the echo function.

echo "I am built in";


In addition to a description of what the function does, the documentation for each function
denotes:
https://quickdraft.pro Sample Test Page 5 of 7
 The name of the function
 Required parameters and their types
 Optional parameters (in square brackets, []), their types, and default values
 The return type of the function (after the final colon, :)

PHP comes with a number of built-in functions. These functions—also known as internal functions
— can be invoked without writing them ourselves. In this lesson, we’ll explore some useful built-in
functions and empower you to discover new built-in functions yourself.
PHP includes useful built-in functions for getting information about
variables. The gettype() function takes a variable as its argument and returns a string value
representing the data type of the argument.
$name = "Aisle Nevertell";
$age = 1000000;

echo gettype($name); // Prints: string

echo gettype($age); // Prints: integer


Notice that we didn’t write a definition for the gettype() function ourselves—it’s built into PHP.
Since the function is included within the language itself, we can just call it anywhere within our PHP
code.
Let’s take a look at another built-in function! The var_dump() function also takes a variable
argument. It prints details about the argument it receives.
var_dump($name); // Prints: string(15) "Aisle Nevertell"

var_dump($age); // Prints: int(1000000)


In the code above, we first used var_dump() to print information about the variable $name. string(15)
—the variable’s type and length—were printed followed by the value held by the variable.
Next, we used var_dump() to print information about the variable $age. Here, the integer is printed
within the parentheses.
PHP has over 1000 built-in functions that can be called directly, from within a script, to perform a
specific task.

https://quickdraft.pro Sample Test Page 6 of 7


Test 2: Write a paragraph explaining the below timeline diagram.

Test 3: Write a procedure explaining adding index entries (main index and sub
index) in word.

https://quickdraft.pro Sample Test Page 7 of 7

You might also like