The following small series for everyone to bring an article on the PHP universal return value setting method. Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.
Encountered a good PHP code. Record it.
When you write PHP code, you often encounter the need to return the value of the situation, you can set the return value of the uniform format.
Here's a good example.
Configuration Class Return.conf.php
<?phpdefine ("Return_val", "Return Array" (' Code ' = 0, ' msg ' = ' = ', ' data ' = '); "); Define ("Return_success", 0); Define ("Return_runtime_err", 1); Define ("Return_file_not_exist", 2); class returnconf{public static function Commonreturn () { return eval (return_val); } }? >
testing, using test.php
<?phprequire_once ("Return.conf.php"); function Get_file_line ($filename) { $result = Returnconf::commonreturn (); $cmd = "Wc-l $filename | awk ' {print '} '; EXEC ($cmd, $output, $code); if (return_success!== $code) {$result [' code '] = Return_runtime_err; $result [' msg '] = "exec $cmd err"; return $result; } $result [' data '] = $output [0]; return $result;} Print_r (Get_file_line ("test.php"));?