PHP - Introduction Variable Name

Introduction

PHP variables start with the $ sign followed by the variable name.

A valid variable name starts with a letter or an underscore followed by any combination of letters, numbers, and/or underscores.

Variable name is case sensitive.

<?php
     $_some_value = 'abc'; // valid 
     $1number = 12.3;      // not valid! 
     $some$signs% = '&^%'; // not valid! 
     $My_2_home = "ok";    // valid 
     $My_2_Home = 'no';    // this is a different variable 
     $isThisCamelCase = true; // camel case 
?>

Everything after // is a comment, and is thus ignored by PHP.

Variable names like $_some_value and $My_2_home are valid.

$1number is not valid as it starts with number.

$some$signs% are not valid as it contains invalid symbols.

$My_2_home and $My_2_Home are two different variables.

Related Topic