LoginSignup
4
4

More than 3 years have passed since last update.

PHPのスプレッド演算子

Posted at
<?php

$arr = [1,2,3,4,5];

function test(int $a, int $b, int $c, int $d , int $e) {
    var_dump($a);
    var_dump($b);
    var_dump($c);
    var_dump($d);
    var_dump($e);
}

// 配列がアンパックされて各要素が引数に渡される
test(...$arr);
// 実行すると以下のアウトプットが出る
// int(1)
// int(2)
// int(3)
// int(4)
// int(5)


?>
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4