Maison >développement back-end >tutoriel php >怎么将两个段代码 合成一个函数

怎么将两个段代码 合成一个函数

WBOY
WBOYoriginal
2016-06-23 14:14:551338parcourir

PHP MySQL ASP C select

//php$query_hx_php= "SELECT * FROM content_publish WHERE content_language_classification = 'php' group by content_original_autor ORDER BY content_id DESC";$record_php = mysql_query($query_hx_php);$record_cnt_php = mysql_num_rows($record_php);//asp$query_hx_asp= "SELECT * FROM content_publish WHERE content_language_classification = 'asp' group by content_original_autor ORDER BY content_id DESC";$record_asp = mysql_query($query_hx_asp);$record_cnt_asp = mysql_num_rows($record_asp);


//我希望 后缀名 如_asp  _php 能根据参数变化 比如我传进来的是c 那么后面变量后缀名统一变成****_c

回复讨论(解决方案)

  function  aa($str){	   $str1 = '$'.$str;       $query_hx_.$str1= "SELECT * FROM content_publish WHERE content_language_classification = 'asp' group by content_original_autor ORDER BY content_id DESC";	   $record_.$str1 = mysql_query($query_hx_asp); 	   $record_cnt_.$str1 = mysql_num_rows($record_asp);    }

变量要那么多干什么

function foo($a){    $query_hx_php= "SELECT * FROM content_publish WHERE content_language_classification = '$a' group by content_original_autor ORDER BY content_id DESC";    $record_php = mysql_query($query_hx_php);    $record_cnt_php = mysql_num_rows($record_php);     return $record_cnt_php;  //返回值根据需要自行修改}

Déclaration:
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