Functions and Arrays in PHP - Formula Sheet
Core Syntax and Formulas
Function Definition Structure
Defines a modular block of code with a unique identifier and optional parameters.
Syntax: function functionName(parameter1, parameter2) { code to execute; }
- function: The mandatory keyword used to initialize a custom function definition.
- functionName: The unique identifier for the function, which must start with a letter or underscore and is case-insensitive.
- parameter1, parameter2: Optional placeholder variables used to receive values during execution.
Function Calling Syntax
Executes a declared function by passing appropriate runtime values.
Syntax: functionName(argument1, argument2);
- argument1, argument2: The actual values or variables passed to the function during invocation.
Indexed Array Initialization
Creates a list of values indexed by sequential integers starting from 0.
Syntax 1: arrayVariable = [value1, value2, value3];
Syntax 2: arrayVariable = array(value1, value2, value3);
Associative Array Initialization
Creates a key-value store using explicit key associations.
Syntax: arrayVariable = array(key1 => value1, key2 => value2);
- key1, key2: Custom labels used as unique index identifiers.
- =>: The key association operator that maps an index key to its corresponding value.
- value1, value2: The data elements of any type stored stored under their respective keys.
Multidimensional Array Element Access
References nested elements inside a layered array structure.
Syntax: arrayVariable[outer_index][inner_index];
- outer_index: The index pointing to the outer array.
- inner_index: The nested index pointing to the specific item inside the inner array.
More for this chapter
Book Back Questions11 textbook MCQs · solved
Additional MCQs15 extra MCQs · solved
Practice TestInteractive · instant score
Book Back TestTest yourself on the textbook set
Additional MCQ TestTest yourself on the extra set
Study NotesConcepts & methods
More chapters in Computer Applications
View all
1 Multimedia
2 An Introduction to Adobe PageMaker
3 Introduction to Database Management System
4 PHP: Hypertext Preprocessor
6 Conditional Statements in PHP
7 Loops in PHP
8 Forms and Files
9 Connecting PHP and MYSQL
10 Introduction to Computer Networks
11 Network Examples and Protocols
12 Domain Name System (DNS)
13 Network Cabling
14 Open Source Concepts
15 E-Commerce
16 Electronic Payment Systems
17 E-Commerce Security Systems
18 Electronic Data Interchange- EDI