PHP函数可以返回很多没有数组的变量吗?
我想这样:
<?PHP public function a() { $a = "a"; $b = "b"; $c = "c"; } echo a()->a; echo a()->b; echo a()->c; ?>
如何访问$a,$b,$c变量?
您可以使用关联数组将其转换为对象,而不是数组,这允许您使用 – >来访问元素.对象语法:
原文链接:https://www.f2er.com/php/135795.htmlfunction a() { return (object) array( 'a' => "a",'b' => "b",'c' => "c"); } echo a()->a; // be aware that you are calling a() three times here echo a()->b; echo a()->c;