PHP Variables Naming

PHP Variables Previous Next PHP Illegal Variables


Variables naming are one of the most important components of programming language.

Variables naming make code more readable, easy to remember and easy to understand.

More than one word variables is difficult to undestand and easy to remember.

For that we have several technique to make code more readable, easy to remember and easy to understand.

Here is list of following technique.

  1. Lower Case
  2. Upper Case
  3. Camel Case
  4. Pascal Case
  5. Snake Case
  6. Hyphen Case

Following technique is nothing but naming style, giving naming style to variables make code more beautiful.

PHP Lower Case Variables Naming.


In lower case each letter start with small letter and all letter are small.

Example


$variables

The following code show you how to make lower case variables in php.

Filename: php / lower-variables.php


Code
<?php
// lower case variables
$variables="hello world in php";
echo $variables;
?>

Running Step.


Type Url - https://localhost/php/lower-variables.php

PHP Upper Case Variables Naming.


In upper case each letter start with capital letter and all letter are capital.

Example


$VARIABLES

The following code show you how to make upper case variables in php.

Filename: php / upper-variables.php


Code
<?php
// UPPER CASE Variables
$VARIABLES="HELLO WORLD IN PHP";
echo $VARIABLES;
?>

Running Step.


Type Url - https://localhost/php/upper-variables.php

PHP Camel Case Variables Naming.


In camel case each word, except the first words, start with a capital letter and all word have first letters is capital except first words.

Example


$myPhpVariables

The following code show you how to make camel case variables in php.

Filename: phpCamelVariables.php


Code
<?php
// camelCase Variables
$myPhpVariables="my Camel Case Php Variables";
echo $myPhpVariables;
?>

Running Step.


Type Url - https://localhost/phpCamelVariables.php

PHP Pascal Case Variables Naming.


In pascal case each words start with a capital letter and all word have first letters is capital.

Example


$MyPhpVariables

The following code show you how to make pascal case variables in php.

Filename: PhpPascalVariables.php


Code
<?php
// PascalCase Variables
$MyPhpVariables="My Pascal Php Variables";
echo $MyPhpVariables;
?>

Running Step.


Type Url - https://localhost/phpPascalVariables.php

PHP Snake Case Variables Naming.


In snake case each word is separated by an underscore (_) called as snake case.

Example


$my_php_variables

The following code show you how to make snake (_) case variables in php.

Filename: php_snake_variables.php


Code
<?php
// snake_case_variables
$my_php_variables="My Snake PHP Variables";
echo $my_php_variables;
?>

Running Step.


Type Url - https://localhost/php_snake_variables.php

PHP Hyphen Case Variables Naming.


In hyphen case each word is separated by an (-) called as hyphen case.

Example


$my-php-variables

The following code show you how to make hyphen (-) case variables in php.

Filename: php / hyphen-variables.php


Code
<?php
// hyphen-case-variables
$my-php-variables="My Hyphen PHP Variables";
echo $my-php-variables;
?>

Running Step.


Type Url - https://localhost/php/hyphen-variables.php


Tags: PHP


Was this helpful ?

Related Code


Popular Code

Latest Code