On this page
- 1 PHP : Function
- 2 PHP : Function
- 2.0.0.1 CRUD App in PHP
- 2.0.0.2 Understanding PHP’s Array Manipulation: Exploring References and Unsetting
- 2.0.0.3 PHP built-in functions
- 2.0.0.4 Mastering Dependency Management with Composer: A Comprehensive Guid
- 2.0.0.5 Associative Array Example in PHP
- 2.0.0.6 Class and Object Example in PHP
- 2.0.0.7 PHP: Sum of two number
- 2.0.0.8 PHP How to get first and last name from full name?
- 2.0.0.9 How to create CSV file in PHP?
- 2.0.0.10 PHP: serialize() Function
- 2.0.0.11 Cheatsheet: PHP
- 2.0.0.12 PHP: global variable
- 2.0.0.13 Understanding PHP Error Reporting Configuration
- 2.0.0.14 PHP: Date and Time Function
- 2.0.0.15 PHP: JSON Encode and Decode
- 2.0.0.16 PHP: Scrap Images Using cURL
- 2.0.0.17 What is curl in php?
- 2.0.0.18 PHP: Quiz App
- 2.0.0.19 PHP Tutorials
- 2.0.0.20 PHP: Arrays
- 2.1 Leave A Comment Cancel reply
PHP : Function
PHP : Function
May 26, 2020
A key benefit of using functions is that they are reusable; if you have a task that needs to be performed a number of times, a function is an ideal solution. They can be either defined by you or by PHP (PHP has a rich collection of built-in functions). This article will focus on programmer-defined functions but will touch briefly on PHP’s functions to complete the picture.
<?php $variable1 = 0; function function1(){ //$variable1 = 10; global $variable1; return $variable1; } function function2(){ //$variable1 = 10; global $variable1; return $variable1; } function add2Numbers($num1, $num2) { $result = $num1 + $num2; return $result; } echo function1(); echo function2(); echo add2Numbers(10,20); /*PHP The static Keyword*/ function myTest() { static $x = 0; echo $x; $x++; } myTest(); myTest(); myTest(); ?>