function x(int ...$numbers)
{
return $numbers;
}
assert(x(...[1, 2, 3]) === [1, 2, 3]);
// 添字配列の添字は消失し、ゼロからの添字に振り直される
assert(x(...[100 => 1, 2, 3]) === [0 => 1, 2, 3]);
try {
// 連想配列はFatal Errorになる。
x(...['a' => 1, 'b' => 2, 'c' => 3]);
assert(false, '例外が発生するから、ここには来ない');
} catch (Error $e) {
assert('Cannot unpack array with string keys' === $e->getMessage());
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
List of users who liked
51