Callback in PHP, is a function which is passed to another function as an argument, This function executes the callback function as needed. Callback function can be a

  1. Regular PHP user-defined function
  2. In-built function.
  3. Object methods
  4. Static class methods
  5. anonymous functions
  6. Arrow functions
  7. Language constructs should not be used as callbacks like array(), echo, empty(), eval(), exit(), isset(), list(), print or unset().

Callback function should be passed as string in argument to another function.

<?php

// Callback function
function myCallback($language) {
   echo "Callback function says Hello From " . $language;
}

// Regular function
function SendName($callback) {
   $myCallback("PHP");
}

//calling regular function with callback function as argument
SendName("myCallback");
?>

Anonymous function (Closures)

<?php
// Anonymous function example
$myCallback = function ($language) {
   echo "Anonymous function says Hello From : $language";
};

// Using the anonymous function
$myCallback("PHP");
?>