web developer

PHP Function

A function is a block of code written in a program to perform some specific task. The defined function can be re-usable. It reduces the time and effort of repetition in a single code. If anything code needs to be changed, we can easily change inside a function the changes will reflect anywhere we call the function.

Types of Functions in PHP

  1. Built-in: These functions are already coded and stored in the form of functions. We just need to call them as per our requirement. for ex:- print_r(),
  2. User-defined: PHP allows us to own a defined function called the user-defined function. Using this we can create our block of code and use it simply anywhere by calling it.
    How can we declare own function;
    syntax, function function_name(){}
    How many types of user-defined function:
    i) Return Type
    ii) Parameterized type
    iii) Return and parameterized type

PHP Classes/Objects: Is is programmer-defined data type and class is the collection of objects. Class is a collection of objects and object store its properties and behavior. It contains class objects and functions that perform a block of code.
How we can declare own class:
class class_name{}
Scope of classes in php
1. Public: There methods and properties are accessible anywhere (outside the class)
2. Private: There methods and properties only accessed within where the class created
3. Protected: Methods and properties can be accessed inside the class where they are declared.