TN Online Testசமச்சீர் கல்விப் பயிற்சி
12ஆம் வகுப்பு கணினி பயன்பாடுகள்

12th Computer Applications PHP Guide: Functions, Syntax and Loops in One Place

இந்தப் பாடத்தைப் பகிரவும்: Telegram

Six of the eighteen chapters in Class 12 Computer Applications are about PHP, so this block carries a large share of the paper. The questions are consistent: they ask about syntax rules, operator names, loop types, file functions and the mysqli functions with their parameter counts. This guide puts all of that on one page with small examples.

PHP basics (Unit 4)

PHP stands for PHP: Hypertext Preprocessor. It is a server-side scripting language, and its files are saved with the .php extension.

<?php
  $name = "Tamil";      // every variable starts with $
  $marks = 95.5;        // float: a decimal number
  echo $name;
?>
  • Eight data types: integer, float, string, boolean, array, object, resource and NULL.
  • Case sensitivity: $Name and $name are different variables, but keywords and function names are not case-sensitive.
  • Operators: = assigns, comparison operators compare two values, and === is called identical because it checks both value and type.

Functions and arrays (Unit 5)

<?php
  function greet() {          // user-defined function
    echo "Welcome";
  }
  greet();                    // calling the function

  $subjects = array("Tamil", "English", "Maths");
  echo $subjects[2];          // Maths
?>
  • A function is a block of code that performs a specific task. Pre-defined functions are called built-in functions.
  • A user-defined function starts with the keyword function.
  • PHP has three types of arrays: indexed, associative and multidimensional.
  • The first index is 0, so in an array of five elements the third element is at index 2.
  • An indexed array can be created with array() or with square brackets, and elements are read with the index in square brackets.

Conditional statements (Unit 6)

<?php
  switch ($day) {
    case 1:  echo "Monday"; break;
    case 2:  echo "Tuesday"; break;
    default: echo "Other day";
  }
?>
  • The simplest conditional statement is if. If its condition is false, the block is skipped.
  • elseif adds further conditions to an if...else chain.
  • In a switch, case gives each option, default runs when no case matches, and break ends the switch.
  • while is not a conditional statement. It is a loop, and it is the answer to the "which is not a conditional statement" question.

Loops (Unit 7)

LoopTypeWhen the condition is checked
forEntry-checkBefore each iteration
whileEntry-checkBefore each iteration
do...whileExit-checkAfter each iteration, so the body runs at least once
foreachArray loopOnce for every element of an array
<?php
  for ($i = 1; $i <= 3; $i++) {   // initialization; condition; increment
    echo $i;
  }

  $array = array(1, 2, 3, 4, 5);
  foreach ($array as $value) {
    echo $value;                    // prints each element in order
  }
?>

The three parts of a for loop are initialization, condition and increment. Initialization runs only once, at the start. The increment part updates the loop variable after every pass.

Forms and files (Unit 8)

  • HTML forms collect input from users and are created with the form tag.
  • Checkboxes allow several selections; radio buttons allow only one at a time.
  • Validation checks the data a user submits. There are two types: client-side and server-side.
<?php
  $file = fopen("notes.txt", "r");               // open
  $text = fread($file, filesize("notes.txt"));   // read
  fclose($file);                                 // close
?>

Connecting PHP and MySQL (Unit 9)

The parameter counts are the most frequently tested detail in this chapter, so learn this table exactly as the textbook presents it.

FunctionPurposeParameters
mysqli_connect()Open a connection4: server name, user name, password, database name
mysqli_query()Run an SQL query2: connection object, SQL query
mysqli_close()Close the connection1: connection object
mysqli_num_rows()Count rows in a result1: result
<?php
  $conn = mysqli_connect("localhost", "root", "", "school");
  $result = mysqli_query($conn, "SELECT * FROM students");
  echo mysqli_num_rows($result);
  mysqli_close($conn);
?>

Two more facts from this chapter: MySQLi functions are supported from PHP version 5, and mysqli_select_data() is not a real function. The correct one is mysqli_select_db().

Practise the PHP block

Work through the chapters in order, because each one uses the previous one: PHP basics, functions and arrays, conditional statements, loops, forms and files and connecting PHP and MySQL. Typing and running the small examples above on your own computer is the fastest way to make the syntax stick.

இந்தப் பாடத்தைப் பகிரவும்: Telegram

Related posts

12ஆம் வகுப்பு கணினி பயன்பாடுகள்

12th Computer Applications Important 1 Mark Questions Chapter Wise

What the one-mark questions in 12th Computer Applications actually test, chapter by chapter: expansions, shortcuts, PHP...

15 Sep 2026 · 4 min read
12ஆம் வகுப்பு கணினி பயன்பாடுகள்

Samacheer Kalvi 12th Computer Applications Book Back Answers: All 18 Chapters

Book back MCQ answers for all 18 chapters of Samacheer Kalvi 12th Computer Applications, with explanations, plus the cha...

15 Sep 2026 · 3 min read
12ஆம் வகுப்பு பொருளியல்

12th Economics: Economists, Institutions and Important Dates in One List

Who said what, which institution does what, and which year matters: the recall facts behind many 12th Economics one-mark...

15 Sep 2026 · 3 min read