About simplifying the code. Seeking the guidance of the Great God

Source: Internet
Author: User
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;
}

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.