Sequential Function Calls in PHP

The result of one function's work can be passed as a parameter to another. In the following example, we will first find the square of the number 2, and then the square of the result:

php<?php
  function func($num) {
    return $num * $num;
  }
  
  $res = func(func(2));
  echo $res; // outputs 16
?>

The functions, of course, do not have to be the same.

Let's say, for example, we have a function that returns the square of a number, and a function that returns the cube of a number:

php<?php
  function square($num) {
    return $num * $num;
  }
  
  function cube($num) {
    return $num * $num * $num;
  }
?>

Let's use these functions to square the number 2, and then cube the result of that operation:

php<?php
  $res = cube(square(2));
  echo $res;
?>

Now let's say we have a function that returns the square of a number, and a function that finds the sum of two numbers:

php<?php
  function square($num) {
    return $num * $num;
  }
  
  function sum($num1, $num2) {
    return $num1 + $num2;
  }
?>

Let's use these functions to find the sum of the square of the number 2 and the square of the number 3:

php<?php
  $res = sum(square(2), square(3));
  echo $res;
?>
Задание 1

Suppose you have a function that returns the cubic root of a number, and a function that rounds a fraction to three decimal places:

php<?php
  function root($num) {
    return pow($num, 1/3);
  }
  
  function norm($num) {
    return round($num, 3);
  }
?>

Using these functions, find the cubic root of the number 2 and round it to three decimal places.