This is a creation in Article, where the information may have evolved or changed.
Before (because too chicken frozen and write the experience record, " see Go Lang's a little introduction, I moved to the heart of"), at that time by the Go language multi-value return of the convenience of moving to the runny nose, because this feature does give us too much convenience and benefits, So, the go language is so close to engineering practice. While PHP does not directly support the return of many in the language, but it provides a language structure such a wonderful existence to assign value.
In PHP, a similar syntax requires an array to be implemented with the language structure of the list. Click here to view the Official Handbook's Instructions for list usage.
This is the official description of the use of list:
Array List ( Mixed $varname [, Mixed $... ] )
< like array () , this is not a real function, but a language structure. list () assigns a set of variables in one-step operation.
Needless to say, give a chestnut:
<?PHP//E.G (1) List ($SUCC, $code, $data) = Array (true, 0, Array (n/a)),//$SUCC: true//$code: 0//$data: Array (n/a)
In the example above, it is simple to assign each element of an array to a variable in the list at once.
Back to the beginning of this article, how does PHP implement multivalued returns compared to the go language? Believe that if you see here, you should also be clear. :-D, if I had to get a chestnut, okay, on the code:
<?php//If we check the database, get the user information function Get_user_info ($uid) {//some code get userinfo from DB. try{$userinfo = db::get_one (Array (' uid ' = = $uid)); $result = Array (true, 0, $userinfo); } catch (\exception $e) {$result = Array (false, $e->getcode (), $e->getmessage ()); } return $result; }list ($SUCC, $code, $data) = Get_user_info, if ($SUCC) {//some thing var_dump ($data);} else{Logger::writeerrorlog ($data, $code); echo $data;//error message}
All languages have their own characteristics, although there is no go language so concise, but eventually it is also a more convenient facilities. With the evolution of PHP, our development has changed, in fact, this sentence is wrong! Because PHP has always followed the best practice of the path forward, so there is a change in language characteristics, have the energy to look at the PHP feature RFC, here are based on actual application scenarios to submit and vote to decide whether to develop. I hope she's getting better, why not?