1
2<?php
3// Coercive mode
4function sumOfInts(int ...$ints)
5{
6 return array_sum($ints);
7}
8
9var_dump(sumOfInts(2, '3', 4.1));
10
11
1
2<?php
3// Fetches the value of $_GET['user'] and returns 'nobody'
4// if it does not exist.
5$username = $_GET['user'] ?? 'nobody';
6// This is equivalent to:
7$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
8
9// Coalescing can be chained: this will return the first
10// defined value out of $_GET['user'], $_POST['user'], and
11// 'nobody'.
12$username = $_GET['user'] ?? $_POST['user'] ?? 'nobody';
13?>
14
15
1
2<?php
3
4function arraysSum(array ...$arrays): array
5{
6 return array_map(function(array $array): int {
7 return array_sum($array);
8 }, $arrays);
9}
10
11print_r(arraysSum([1,2,3], [4,5,6], [7,8,9]));
12
13