Welcome to all our readers on our website at www.tutorialpath.com. As you all know that here on our website we will provide you lots of information related to the latest and newly introduced technology which help you to get updated with the latest tech. Here you will get all the useful information which is required in this tech world. As you know technology is one of the trending part in this world. So, here again we came up with a latest and new tech information which is related to the process of creating Variable In PHP. With the help of this article you will get to know the complete process of how to create How to define variable in php a step by step manner. So, simply have a look to this article and grab all the useful information which is going to be very helpful for you.
What is Variable in PHP
Variable are “containers” for storing information.
All variable in PHP start with a $ (dollar) sign followed by the name of the variable.
A valid variable name starts with a letters, numbers, or underscore (_), followed by any number of letters, number of letters, number, or underscores.
If a variable name is more than one word, it can be separated with underscore.
Syntax of declaring a variable in PHP is given below:
PHP has a total of eight data types which we use to construct our variables −
- Integers − are whole numbers, without a decimal point, like 4195.
- Doubles − are floating-point numbers, like 3.14159 or 49.1.
- Booleans − have only two possible values either true or false.
- NULL − is a special type that only has one value: NULL.
- Strings − are sequences of characters, like ‘PHP supports string operations.’
- Arrays − are named and indexed collections of other values.
- Objects − are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class.
- Resources − are special variables that hold references to resources external to PHP (such as database connections).
The first five are simple types, and the next two (arrays and objects) are compound – the compound types can package up other arbitrary values of arbitrary type, whereas the simple types cannot.
PHP Variable: Declaring string, integer and float
Let’s see the example to store string, integer and float values in PHP variables.
PHP Variable: Sum of two variables