<?php
/**
* @param int $num1
* @param ?int $num2 If null or omitted, it will get the value 1
*
* @return int
*/
function add($num1, $num2 = null) {
// If the default value is null, set it to the default
$num2 = $num2 ?? 1;
print_r($num1, $num2);
return $num1 + $num2;
}
$bool = true;
echo add(5, $bool ? 5 : null) . PHP_EOL;
$bool = false;
echo add(5, $bool ? 5 : null) . PHP_EOL;