because we are on the internet.

PHP Variables

A variable is something for storing information.

Variables in PHP

Variables are used for storing a values, such as arrays, numbers or text strings.

Once a variable is declared, it could be used in your script, over and over again.

In PHP, all variables start with a $ (dollar) sign symbol.

Below tells how to correctly declare a variable in PHP script:

<?php $var_name = value; ?>

If you forget the $ sign at the very beginning of your variable, your variable will not work.

Below, we declare a variable contains a number and a variable contains a string:

<?php

$txt = “Hello World”;

$number = 16;

?>

PHP is a loosely Typed Language

In PHP, users do not need to declared a variable before adding any value to it.As what showed above, users do not need to tell the PHP what kind of data type the variable is.PHP is able to converts the variable for the correct data type, all depending on the value of variable.In some other strongly typed programming language, users need to declare the data type and name of a variable before using it.

In PHP, variables are automatically declared.

Rules for Naming Variables

A variable in PHP must be started with an underscore”_” or a letter

A variable name only contains underscores and alpha-numeric characters (0-9,a-z, A-Z, and _ )

A variable can not contain spaces. In case, a variable contains more than one word, users can separate it with capitablization ($myString) or with underscores ($my_string)

Leave a comment

You must be logged in to post a comment.

 

About Author

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vestibulum at arcu. Integer et risus. Morbi id tellus. Integer felis. Mauris malesuada, turpis vitae facilisis euismod, dui arcu adipiscing sem, eu vulputate leo ante in lacus. Sed porta accumsan lectus. Aenean ac sem. In consequat tempus velit. Phasellus leo enim, adipiscing a, egestas nec, pretium ut, pede. Mauris sollicitudin diam et mauris. Sed quis enim vel augue egestas lobortis. Etiam tempus ipsum vel neque.