php模仿go实现多变量返回
作者:互联网
2021年5月25日18:40:56
环境php8.0.3
class IndexOpenController extends BaseController { public function test(Request $request) { [$t1, $u1] = $this->zx(); p($t1); p($u1); } public function zx() { $t = 22; $u = 33; return [$t, $u]; } }
是从PhpSpreadsheet源代码看到写法,代码方便一些
更多返回
class IndexOpenController extends BaseController { public function test(Request $request) { [$u1, $u2, $u3] = $this->zx(); p($u1); p($u2); p($u3); } public function zx() { $t1 = 22; $t2 = 33; $t3 = 44; return [$t1, $t2, $t3]; } }
只接受部分
class IndexOpenController extends BaseController { public function test(Request $request) { [$u1, $u2] = $this->zx(); p($u1); p($u2); // p($u3); } public function zx() { $t1 = 22; $t2 = 33; $t3 = 44; return [$t1, $t2, $t3]; } }
标签:function,t2,u1,t1,zx,go,php,public,模仿 来源: https://www.cnblogs.com/zx-admin/p/14810072.html