PHP Programming : Variables and Data type

in #esteem7 years ago (edited)

Hi steemian...
On this occasion I will continue my discussion of php.

Variables and Data types

A variable is a symbol representing a particular value or a declaration of something that has a fluctuating value. In PHP language, variables start with a $ sign. For example the variable name a, then written with $ a.

The rules of writing variables include the following:

There are only three characters that can be used variable names such as letters, numbers, and underscores.
The first character after the $ sign must be a letter or underscore.
If variable names are more than one word, there should be no space between them.
PHP variables are case sensitive, ie distinguish between uppercase and lowercase for the variable name, so it will be different between $ Try with $ COBA. Each variable has its own data type.

PHP does not require defining variables, the data type will automatically change by the operator used, because PHP uses Type Juggling. But in addition to using Type Juggling, PHP also uses Type Casting, which can manually specify the type of data in question.

Type Juggling is the behavior or nature of PHP variables that will automatically change the data type of the variable depending on the operator used when entering the contents of the variable.
Example:

Results

Constants

After we discussed about the variables in php on this occasion we will discuss about the constant in PHP.

PHP provides 2 types of storage place of values ie variables (variables) and constants (constant), so the constants themselves function the same as the variable that is storing the value, but the difference between the stored value of the constant can not be changed.

Because of its fixed value nature, constants are often used for configuration data, such as server names, database names, etc.
Example:

Results

Operator

As the name implies, the comparison operator compares the value of 2 operands. The result is always one of TRUE or FALSE. The comparison result will be TRUE if the comparison condition is true, or FALSE if the condition is wrong.

The operand for this comparison operator can be a data type of numbers (integer or float), as well as a string type. The comparison operator checks the value and (for some operators) also the data type of the operand.
Example:

Results

Example

Results

Example

Results

Comment

Comments are needed to provide explanations to others who read our code. The full comment will be ignored by PHP at the time of execution. Though you may think that only you will read the program code, but that is a good idea. I myself am often confused when understanding a few lines of program code after few months of not seeing it.

A good comment is a short and not very long commentary, but gives an explanation of the usefulness of the code or that variable was created.

Aside from being a place to make an explanation, the nature of comments that will not be executed by PHP, provides another advantage in the process of making the program. I often make some lines of program code as a comment when searching for the cause of the error code of the program being created (debugging process).

PHP provides several ways to make comments, and they all come from other popular programming languages like C, C ++, and Unix Shell.
Example:

Results

Thank you for your attention may be useful to all readers.


Source

[CODEPOLITAN]


Don't forget upvote and follow me @muadzis and see you next time