About simplifying code. Seeking the guidance of the Great God
It's half a month to mingle with CSDN. A lot of harvest, want to settle here.
Like the atmosphere here, like the great God here.
if (empty ($grouptypeid)) {
ShowMsg (' Please specify your own exam! ', '-1 ');
Exit ();
}if (Empty ($content)) {
ShowMsg (' content cannot be empty! ', '-1 ');
Exit ();
}if (Empty ($teachername)) {
ShowMsg (' Please choose teacher! ', '-1 ');
Exit ();
}if (Empty ($years)) {
ShowMsg (' Please select the date ', '-1 ');
Exit ();
}if (Empty ($isupdate)) {
ShowMsg (' Please select Update Date ', '-1 ');
Exit ();
}
How is this easy to write?
Share to: more
------Solution--------------------
The simplification of this code should be done when the relevant variable is assigned a value
You're doing the validation of the incoming data, apparently tangible as
$grouptypeid = $_post[' Grouptypeid ');
Such a code snippet
So there are
$dict = Array (
' Grouptypeid ' = ' Please specify your own exam! ',
' content ' = ' contents cannot be empty! ',
' TeacherName ' = ' Please choose a teacher! ',
' Years ' = ' Please select the date ',
' Isupdate ' = ' Please select the update Date ',
);
foreach ($_post as $k = = $v) {
if (empty ($v)) {
ShowMsg ($dict [$k], '-1 ');
Exit
}
$ $k = $v;
}