What is the Variable And how does it work?

The variable is seen here as a container, which you can use to store data information. It doesn’t make any difference to him, so it becomes easy to learn php.

Type of variable:-

  • -Local variable
  • -Global variable
  • -Static variable

Variable Declaration

The variable has to start with a $ sign, and you have to type a name with it. By combining these two, it will be called a variable of php.

Ex: $roll
    $price
    $name

RULE

When you write the variable name, What is the rule, and what should be kept in mind?

Variable names must always start with $.

  • The first word after the $ sign must be either a letter or an underscore(_).
  • Variable names will not start with numbers. The number cannot be given after the $ sign. Can give any letter or underscore.
  • A variable name that is case-sensitive. This means that num you have written in small and NUM you have written in the capital will be considered different and will not be considered the same.
  • You cannot put a predefined constant in a variable name, such as PHP_VERSION, PHP_OS is a predefined constant.

Variable initialization

Whenever you write a variable name, it does not know what kind of data will be kept in it or what kind of data this variable has to hold. It is not known to that variable, but as soon as you assign the value, that variable automatically understands the data tag. If someone assigns an integer value to that variable, then that variable understands that my data type is an integer. If someone assigns a string, then it understands that my data type is a string.

If you declare any variable in php, it is always assigned before using it. This means you have not given value to any variable and if you want to assess then it will not be assessed.

So keep in mind that whenever you are evaluating a variable in php its value must be already assigned.

Ex:- $roll=265;
     $price= 25.50;
     $name="geeky shows";

Note-

<?php
	$roll  = 565;
	echo $roll;
?>

Can write in numeric without even a column

<?php
	$roll  = "name";
	echo $roll;
?>

But always write the name with a semi-column.

Related Posts

Associative Array in PHP?

An associative array is a simple and very important array of PHP. This array is also used the most, it is very easy to understand this array,…

How to work in functions PHP?

If there is any task in your program which you train to execute repeatedly then instead of writing the code for that task at a different place…

For Loofs in PHP

In for-loop initialization, condition and increment happen on the same line. The loop keeps on repeating as long as the condition is true. When the for loop…

If Else Conditionals in Php?

If Else statement is the most important feature of any programming language, PHP is used to run any Code Of Block according to If Else conditions. This…

What are operators in PHP? PHP – Operator Types

Operators are used to developing data. In Programming Languages, Operators are taken from Mathematics and Operator Programmers work with Data. An operator is a chain of symbols…

String Functions in PHP?

When many characters are written together in sequence, they form a string. For example, India is a string. It is made up of i, n, d, i,…

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x