Variables in PHP

Variables in PHP
 
Variables in PHP
  • Currently 0 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Rating: 0/5 (0 votes cast)

Thank you for rating!

You have already rated this page, you can only rate it once!

Your rating has been changed, thanks for rating!

Log in or create a user account to rate this page.


As in any other programming language, PHP has such things as variables.

When programming in PHP one shouldn't forget to declare new variables. The principles of saving memory that were relevant several years ago are now not taken into account. However, if you keep large amounts of memory in the variables, it's better to delete unused variables, using the operator unset.

In general, a variable - is a part of RAM memory, which can be accessed by name. All the data with which the program is working, are stored in variables (the exception is a constant, which, may contain only a number or a string). No such thing as a pointer (as in C) exists in PHP - when assigned the variable is entirely copied, whatever complicated structure it may have. However, in PHP, starting with version 4, there is a concept of links - hard and symbolic.

The names of all the variables in PHP must start with the dollar sign $ - because for the interpreter it is much easier to "understand" and recognize them, especially in strings. Names of variables are case sensitive, for example, $variable is not the same as $Variable or $VARIABLE:

The official PHP documentation states that the name of the variable may consist not only of Latin alphabet and numbers, but also of any characters, ASCII code which is older than 127, - in particular, of Cyrillic characters, also known as "Russian" letters. But it is not recommended to use the Cyrillic alphabet in these names - considering the fact that in various encodings the letters have different codes. But if you wish, go and experiment and do as you see fit.

We can say that variables in PHP - are special objects that can contain absolutely anything.

Here are some examples of variables in PHP:

$variable = 'Ronald';
$Variable = 'William';
echo "$variable, $Variable"; // displays "Ronald, William"

$6var= 'test'; // incorrect, begins with a number
$_6var = 'test'; // correct, begins with an underscore
$tдyte = 'test'; // correct, 'д' is (Extended) ASCII 228.

A distinctive advantage of PHP is that it is not necessary either to define the variables explicitly or to specify their type. All of this is done by the interpreter. However, sometimes the interpreter can be wrong (for example, if the text string contains a decimal), so occasionally it is necessary to specify the type of a particular expression.

A little more often it is necessary to find out the type of the variable (for example, expressed in function parameters) while the program is run. 


 

Read also

What is PHP?

What is PHP?

Classes and objects in PHP

Classes and objects in PHP

How to access classes and objects in PHP

How to access classes and objects in PHP

Post comment

basicuse.net
html5_css
106160485398655174790

Quick navigation

General navigation