Skip to content
Quiz · Functions as values · lesson 2 of 8

Quiz — a function as an argument

What does the program print?

PHP
<?php

function applyTwice(callable $f, int $x): int
{
    return $f($f($x));
}

$inc = function (int $n): int {
    return $n + 3;
};
echo applyTwice($inc, 1), ' ', applyTwice('abs', -5), "\n";