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

Functions and Array

Uploaded by

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

Functions and Array

Uploaded by

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

1.

Functions
1. Defining and Calling Functions:
• Defining Functions: Functions in PHP are
defined using the function keyword, followed
by the function name, parentheses (), and a
block of code enclosed in {}.

• Calling Functions: You can call a function by


using its name followed by parentheses.

2. Function Parameters:
• Functions can take parameters to work with
different inputs.
3. Return Values:
• Functions can return values using the return
statement.

4. Variable Scope:
• Local Scope: Variables defined within a
function are local to that function.
• Global Scope: Variables defined outside any
function have a global scope and can be
accessed anywhere outside functions. To
access them inside functions, use the global
keyword.
5. Built-in Functions:
• PHP comes with many built-in functions for
different tasks, such as strlen() for string
length, array_merge() for merging arrays, etc.

2.Arrays
1. Indexed Arrays:
• Arrays with a numeric index.

2. Associative Arrays:
• Arrays with named keys.
3. Multidimensional Arrays:
• Arrays containing one or more arrays.

4. Array Functions:
• PHP provides various functions for working
with arrays.
o count(): Returns the number of elements
in an array.
o array_merge(): Merges one or more
arrays.
o array_push(): Adds one or more elements
to the end of an array.
o array_pop(): Removes the last element of
an array.

You might also like