Exercise: Writing an AUTOLOAD Function

Implement the incrementer and decrementer functions with the AUTOLOAD() function.

Problem statement

In this challenge, make an AUTOLOAD() function, the details of which are given below:

Assume that the $count = 0 variable is predefined:

  • If an undefined function named increment is called with parameter n, $count should be incremented by n.

  • If an undefined function named decrement is called with parameter n, $count should be decremented by n.

  • If any other undefined function is called, the value of $count should remain the same.

  • At the very end of the function, print the value of $count like this:

Get hands-on with 1400+ tech skills courses.