有三个功能。其中两个函数使用一些完全相同的变量,因此我创建了第三个函数,但变量无法传递给这两个函数。
修改的 我需要更详细的内容。两个函数是相同的search()和report(),但当然也会有差异。
搜索()
public function search(){
if(($_POST['number'] != null) && (is_numeric($_POST['number']))){
$number = trim($_POST['number']);
}else{
$number = "";
}
if (($_POST['name'] != null)) {
$name = strtoupper(trim($_POST['name']));
}else{
$comments = "";
}
if($_POST['date'] != null){
$date = trim($_POST['date']);
$parseDate = explode("/", $date);
$newDate = $parseDate[2].$parseDate[0].$parseDate[1];
}else{
$newDate = null;
}
//something will be done here//
//will require using all 3 of the variables above
}
报告()
public function report(){
if(($_POST['number'] != null) && (is_numeric($_POST['number']))){
$number = trim($_POST['number']);
}else{
$number = "";
}
if (($_POST['name'] != null)) {
$name = strtoupper(trim($_POST['name']));
}else{
$comments = "";
}
if($_POST['date'] != null){
$date = trim($_POST['date']);
$parseDate = explode("/", $date);
$newDate = $parseDate[2].$parseDate[0].$parseDate[1];
}else{
$newDate = null;
}
//something will be done here//
//will require using all 3 of the variables above
}
结合()
public function combine(){
//as can be seen. The above two functions are totally the same but after that where I commented "something will be done here" different things would be done with different output.
}
search()
和report()
最终会使用json_encode将一些数据传回客户端。