# Higher Order Functions

#### IBM Rational Functional Tester

32 Lectures 3.5 hours

#### Functional Fitness training – Discover the easy way to get in shape at home

11 Lectures 1 hours

#### Functional Programming and Lambda- Learn Java8 by Coding it

Best Seller

72 Lectures 10.5 hours

A higher order function (HOF) is a function that follows at least one of the following conditions −

• Takes on or more functions as argument
• Returns a function as its result

## HOF in PHP

The following example shows how to write a higher order function in PHP, which is an object-oriented programming language −

```<?php
\$twice = function(\$f, \$v) {
return \$f(\$f(\$v));
};

\$f = function(\$v) {
return \$v + 3;
};

echo(\$twice(\$f, 7));
```

It will produce the following output −

```13
```

## HOF in Python

The following example shows how to write a higher order function in Python, which is an object-oriented programming language −

```def twice(function):
return lambda x: function(function(x))
def f(x):
return x + 3
g = twice(f)
print g(7)
```

It will produce the following output −

```13
```