Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

9. Control Structures

Lesson 10 of 36 in the free Web Based Programming notes on Siksha Sarovar, written by Rohit Jangra.

2. Conditional Statements (Control Structures) in PHP

Conditional statements represent the decision-making process in programming.

2.1 if Statement Executes code if the condition is true.

        $age = 20;
        if ($age >= 18) {
          echo "Eligible to vote";
        }

2.2 if–else Statement Executes one block if condition is true, otherwise another block.

        $marks = 45;
        if ($marks >= 40) {
          echo "Pass";
        } else {
          echo "Fail";
        }

2.3 if–elseif–else Statement Used to test multiple conditions.

        $marks = 75;
        if ($marks >= 80) {
          echo "Grade A";
        } elseif ($marks >= 60) {
          echo "Grade B";
        } else {
          echo "Grade C";
        }

2.4 Nested if Statement An if statement inside another if statement.

        $age = 22;
        $citizen = true;

        if ($age >= 18) {
          if ($citizen) {
            echo "Eligible to vote";
          }
        }

2.5 switch–case Statement Used when there are multiple fixed values.

        $day = 3;
        switch ($day) {
          case 1:
            echo "Monday";
            break;
          case 2:
            echo "Tuesday";
            break;
          case 3:
            echo "Wednesday";
            break;
          default:
            echo "Invalid day";
        }

Important Points: • break stops execution • default executes if no case matches