Extract the part to be executed every time out of php. There are three functions in total, and the vast majority of them are the same. How can we become a function more scientifically to achieve efficiency. Method 1: how can we convert these three functions into one? Method 2: The execution body of the three functions is the public part of the output. How can this problem be achieved ????? Function & nbsp; wc1 ($ SQL) {$ tb = 'extract the part to be executed each time
In php, there are three functions with the same scores. How can we become a function more scientifically to achieve efficiency.
Method 1: how can we convert these three functions into one?
Method 2: The execution body of the three functions is the public part of the output. How can this problem be achieved ?????
Function wc1 ($ SQL ){
$ Tb = '';
$ ShowArr = array ();
$ Q = $ this-> getAll3 ($ SQL );
While ($ r = $ q-> fetch_array (MYSQLI_USE_RESULT )){
$ Tb. =''. $ R ["number"].'';
$ Tb. = isset ($ this-> show ["customer"])? ''. $ R ["customer"].'': NULL;
$ Tb. = isset ($ this-> show ["orderNo"])? ''. $ R ["orderNo"].'': NULL;
}
Return $ tb;
}
Function wc2 ($ SQL ){
$ Tb = '';
$ ShowArr = array ();
$ Q = $ this-> getAll3 ($ SQL );
While ($ r = $ q-> fetch_array (MYSQLI_USE_RESULT )){
$ Tb. =''. $ R ["number"].'';
$ Tb. = isset ($ this-> show ["customer"])? ''. $ R ["customer"].'': NULL;
$ Tb. = isset ($ this-> show ["orderNo"])? ''. $ R ["orderNo"].'': NULL;
$ Tb. = isset ($ this-> show ["name"])? ''. $ R ["name"].'': NULL;
$ Tb. = isset ($ this-> show ["wc"])? ''. $ R ["wc"].'': NULL; // ---------------- changes here
}
Return $ tb;
}
Function wc3 ($ SQL ){
$ Tb = '';
$ ShowArr = array ();
$ Q = $ this-> getAll3 ($ SQL );
While ($ r = $ q-> fetch_array (MYSQLI_USE_RESULT )){
$ Tb. =''. $ R ["number"].'';
$ Tb. = isset ($ this-> show ["customer"])? ''. $ R ["customer"].'': NULL;
$ Tb. = isset ($ this-> show ["orderNo"])? ''. $ R ["orderNo"].'': NULL;
$ Tb. = isset ($ this-> show ["name"])? ''. $ R ["name"].'': NULL;
$ Tb. = isset ($ this-> show ["fsaww"])? ''. $ R ["sfs3"].'': NULL; // ---------------- changes here
}
Return $ tb;
}
------ Solution --------------------
Function wc ($ SQL ){
$ Tb = '';
$ ShowArr = array ();
$ Q = $ this-> getAll3 ($ SQL );
$ Dict = array ('fsaww '=> 'sfs3'); // the comparison table is shown here.
While ($ r = $ q-> fetch_array (MYSQLI_USE_RESULT )){
$ Tb. =''. $ R ["number"].'';
Foreach ($ this-> show as $ k ){
If (isset ($ dict [$ k]) $ k = $ dict [$ k];
$ Tb. =''. $ R [$ k].'';
}
}
Return $ tb;
}
------ Solution --------------------
function wc1($sql, $assoc = array()){
$tb='';
$showArr = array();
$q=$this->getAll3($sql);
while ($r=$q->fetch_array(MYSQLI_USE_RESULT)) {
$tb.=''.$r["number"].'';
if(count($assoc)){
foreach($keys as $k => $v){
$tb .= isset($this->show[$k]) ?''.$r[$v].'':NULL;
}
}
}
return $tb;
}
wc1($sql, array('customer' => 'customer', 'orderNo' => 'orderNo'));
wc1($sql, array('customer' => 'customer', 'orderNo' => 'orderNo', 'name' => 'name', 'wc' => 'wc'));
wc1($sql, array('customer' => 'customer', 'orderNo' => 'orderNo', 'name' => 'name', 'fsaww' => 'sfs3'));