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

PHP explode() Function Example Tutorial

A PHP explode function example is given in this article. I will demonstrate how to use PHP’s explode string to array function. This is a basic example…

How to Convert Array to String in PHP?

We will cover the example of converting an array to a string in PHP in this lesson. We’ll examine an example of converting an array to a…

How Can I Convert a String in PHP Into an Array?

We will go over how to transform a string into an array in PHP in this little tutorial. Describe how to convert a string value into an…

How to Use the array_merge() Function in PHP?

We will go over the simple and quick method to use the PHP array_merge() function example in this brief tutorial. Let’s talk about the PHP example of…

How to Merge Two Arrays in PHP?

I explained simply how to merge two arrays in PHP Laravel. you will learn how to append two arrays in PHP. you will learn how to merge…

How to Get the First 5 Elements of Array in PHP?

Here, I will show you the php array to get the first 5 elements. let’s discuss about php array getting 5 first element values. you can see…

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