Page 194 - CITS - Computer Software Application -TT
P. 194
COMPUTER SOFTWARE APPLICATION - CITS
The break Statement
With the break statement we can stop the loop even if it has not reached the end:
Example:
Stop the loop if $x is “blue”:
The continue Statement
With the continue statement we can stop the current iteration, and continue with the next:
Example:
top, and jump to the next iteration if $x is “blue”:
Functions in PHP
Functions in PHP
In this section, we’ll explore the fundamental concepts of functions in PHP. Understanding the role of functions in
programming and how they contribute to code organization and reusability is crucial. We’ll cover:
• What are Functions: Explanation of the concept of functions in programming.
• Why Use Functions: Benefits of using functions, such as code modularity and maintainability.
• Function Syntax: An overview of the basic structure of PHP functions
Introduction to Functions
In modern programming, functions play a vital role in organizing code and promoting reusability. They encapsulate
a set of instructions and can be called upon to perform a specific task. Let’s explore the core concepts:
What are Functions:
A function is a block of code that performs a specific task. It enhances code modularity, making it easier to
understand and maintain. Functions can be reused in different parts of a program.
The real power of PHP comes from its functions.
PHP has more than 1000 built-in functions, and in addition you can create your own custom functions.
Example:
Why Use Functions:
Code Organization: Functions help break down a program into smaller, manageable pieces.
Reusability: Once defined, functions can be reused, reducing redundancy in your code.
Function Syntax:
In PHP, a basic function looks like this:
Defining Functions:
Let’s dive into the process of creating and using custom functions in PHP.
Function Declaration:
To declare a function, use the `function` keyword, followed by the function name, and a pair of parentheses.
181
CITS : IT&ITES - Computer Software Application - Lesson 47 - 62