把每次都要执行的部分抽出来
php中,共有3个函数,其中绝大分数是相同的。如何能更科学的变成一个函数,从而搞效率。
方法一:将此3个函数变成一个,怎么实现呢?
方法二:奖此3个函数的执行体,就是输出的部分公共部分,单独做个函数。如何实现呢?????
1 | function wc1( $sql ){<br /> <br /> $tb = '' ;<br /> $showArr = array ();<br /> $q = $this ->getAll3( $sql );<br /> while ( $r = $q ->fetch_array(MYSQLI_USE_RESULT)) {<br /> $tb .= '<tr><td>' . $r [ "number" ]. '</td>' ;<br /> $tb .=isset( $this ->show[ "customer" ])? '<td>' . $r [ "customer" ]. '</td>' :NULL;<br /> $tb .=isset( $this ->show[ "orderNo" ])? '<td>' . $r [ "orderNo" ]. '</td>' :NULL;<br /><br /><br /> }<br /> return $tb ; <br />}<br /> function wc2( $sql ){<br /> <br /> $tb = '' ;<br /> $showArr = array ();<br /> $q = $this ->getAll3( $sql );<br /> while ( $r = $q ->fetch_array(MYSQLI_USE_RESULT)) {<br /> $tb .= '<tr><td>' . $r [ "number" ]. '</td>' ;<br /> $tb .=isset( $this ->show[ "customer" ])? '<td>' . $r [ "customer" ]. '</td>' :NULL;<br /> $tb .=isset( $this ->show[ "orderNo" ])? '<td>' . $r [ "orderNo" ]. '</td>' :NULL;<br /> $tb .=isset( $this ->show[ "name" ])? '<td>' . $r [ "name" ]. '</td>' :NULL;<br /> $tb .=isset( $this ->show[ "wc" ])? '<td>' . $r [ "wc" ]. '</td>' :NULL;
|
Copier après la connexion
------解决方案--------------------1 | function wc( $sql ){<br /> $tb = '' ;<br /> $showArr = array ();<br /> $q = $this ->getAll3( $sql );<br /> $dict = array ( 'fsaww' => 'sfs3' );
|
Copier après la connexion
------解决方案--------------------
1 2 3 4 5 6 7 8 | <?php <br /> function wc1( $sql , $assoc = array ()){<br><br> $tb = '' ;<br> $showArr = array ();<br> $q = $this ->getAll3( $sql );<br> while ( $r = $q ->fetch_array(MYSQLI_USE_RESULT)) {<br> $tb .='<tr>
<td> '.$r["number"].' </td> ';<br> if(count($assoc)){<br> foreach($keys as $k => $v){<br> $tb .= isset($this->show[$k]) ?' <td> '.$r[$v].' </td> ':NULL;<br> }<br> }<br> }<br> return $tb;<br>}<br><br>wc1($sql, array(' customer ' => ' customer ', ' orderNo ' => ' orderNo '));<br>wc1($sql, array(' customer ' => ' customer ', ' orderNo ' => ' orderNo ', ' name ' => ' name ', ' wc ' => ' wc '));<br>wc1($sql, array(' customer ' => ' customer ', ' orderNo ' => ' orderNo ', ' name ' => ' name ', ' fsaww ' => ' sfs3'));<div class = "clear" >
</div>
</tr>
|
Copier après la connexion
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn