Elegant ways to return multiple values from a function

后端 未结 14 910
梦谈多话
梦谈多话 2020-12-15 03:49

It seems like in most mainstream programming languages, returning multiple values from a function is an extremely awkward thing.

The typical soluti

14条回答
  •  余生分开走
    2020-12-15 04:42

    PHP example:

    function my_funct() {
        $x = "hello";
        $y = "world";
        return array($x, $y);
    }
    

    Then, when run:

    list($x, $y) = my_funct();
    echo $x.' '.$y; // "hello world"
    

提交回复
热议问题