Valgfrie funktionsparametre i PHP

Funktionsparametre kan gøres valgfrie. For at gøre dette skal parametrene tildeles standardværdier. Lad os for eksempel antage, at vi har følgende funktion:

php<?php
  function func($num) {
    echo $num ** 2;
  }
?>

Lad os gøre det således, at denne parameter som standard har værdien 0:

php<?php
  function func($num = 0) {
    echo $num ** 2;
  }
?>

Lad os teste vores funktion med en parameter:

php<?php
  func(2); // vil udskrive 4
?>

Lad os teste vores funktion uden en parameter:

php<?php
  func(); // vil udskrive 0
?>
Задание 1

Givet funktionen:

php<?php
  function func($num = 5) {
    echo $num * $num;
  }
?>

Denne funktion kaldes på følgende måde:

php<?php
  func(2);
  func(3);
  func();
?>

Forklar, hvad resultatet af hvert af funktionskaldene vil være.

Задание 2

Givet funktionen:

php<?php
  function func($num1 = 0, $num2 = 0) {
    echo $num1 + $num2;
  }
?>

Denne funktion kaldes på følgende måde:

php<?php
  func(2, 3);
  func(3);
  func();
?>

Forklar, hvad resultatet af hvert af funktionskaldene vil være.