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, we can define Conditional function, Function within Function and Recursive function also.
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.
PHP Functions Example:
php
function sayHello(){
echo "Hello PHP Function";
}
sayHello();//calling function
PHP Function Arguments:
We can pass the information in PHP function through arguments which is separated by comma.
PHP supports Call by Value (default), Call by Reference, Default argument values and Variable-length argument list.
The break and continue both are used to skip the iteration of a loop. These keywords are helpful in controlling the flow of the program. Difference between break and continue:
The break statement terminates the whole iteration of a loop whereas continue skips the current iteration.
The break statement terminates the whole loop early whereas the continue brings the next iteration early.
In a loop for switch, break acts as terminator for case only whereas continue 2 acts as terminator for case and skips the current iteration of loop.
For Code Please Visit:
https://github.com/Umii010/PHP-Lectures
Do Like Subscribe and Share with Your Friends Keep Learning and Keep Exploring.
#php functions #php function call #what is function in php #php course #umer shahzad in php #SZABIST Islamabad