Learn with Yasir
Share Your Feedback

Case Sensitivity in PHP: Keywords, Functions, and Variables Explained


Learn about case sensitivity in PHP. Understand how PHP treats keywords and functions as case-insensitive, while variables are case-sensitive, with clear examples.

Case Sensitivity

Keywords and Functions

  • PHP keywords and functions (e.g., if, else, echo) are not case-sensitive.

Variables

  • Variables are case-sensitive, meaning $Var and $var are two different variables.

Example: Case Insensitivity in PHP

<?php
ECHO "Hello World!<br>";
echo "Hello World!<br>";
EcHo "Hello World!<br>";
?>

Example: Case Sensitivity in Variables

<?php
$color = "red";  // lowercase
$COLOR = "green";  // uppercase
echo "My car is " . $color . "<br>";  // outputs red
echo "My house is " . $COLOR . "<br>";  // outputs green
?>

Tasks

Task 1: Experiment with echo

  • Write a PHP script where you use echo, ECHO, and EcHo to print the same message (e.g., β€œHello, PHP!”).
  • Observe the output. Does it work the same way for all variations?

Task 2: Test Variable Names

  • Declare two variables:
    $name = "Alice";
    $NAME = "Bob";
    
  • Print both variables. Are they treated as the same or different?

🧠 Practice & Progress

Explore More Topics

PHP Basics

More ...