What You Should Know About Variables in PHP – Coding Cyber

What You Should Know About Variables in PHP

What You Should Know About Variables in PHP

Other Articles in PHP Data Types Section

Quickly Navigate to Other Sections in PHP Tutorials

PHP Basics
PHP Data Types
PHP Advanced Data Types
PHP Logical Statements
PHP Operators
PHP Loops
User Defined Functions in PHP
Useful PHP Functions

Variables have important significance in PHP programs, For storing any kind of data we will be using variables. In database-driven applications, these variables will be used. Variables are defined with a dollar symbol in front of the variable.

In variables, there won’t be any spaces. This is important to remember. Don’t use hyphens and underscores in variables.

You can use camel case letters to identify another word in variables.

For example, if you want to create a variable with the name of my variable. Please go through below statements to understand the best ways to define variables.


Wrong statements to define variables

$my variable

If you have multi-word terms use Camel case lettered variables.

We can store any kind of data in variables. Like we can store Lines of text in a variable, this (Lines of text) is called in any programming language as strings. We can store Numbers, this is called as integers. We can store numbers with decimal points, this is called as float in PHP technical terms

Now you have clear understanding of what are variables & how you can use them and the best way’s to write variable in your programs.

Using Variables in PHP

Using Variables, variables are important in PHP programs. We can store line of text in variables, this is called as strings in PHP. We can store numbers, this is called as integers. We can store number with decimal values, this is called as float.

First we will start with storing text data in variable. To store data simply create a php file, and start with opening php tag.

For more information access this page.

After that define the variable, and put equals to symbol. What ever you want to store, put that text in quotation marks. Either that can be single quotes or double quotes.

To end that statement use semicolon after closing quotation mark. By doing this, you can create a new statement right after the old statement.

$myvar = "This is simple text";

This above method is for storing data in strings. For storing numbers also it’s same but we don’t use quotation marks around the value. We can use this variable to output the value.

$x = 5;

And after the above statement you can write new statement, because we are closing it with semicolon.

Next thing is to store number with decimal point, this is called as float. This can be done same way as the above.

$y = 5.5;

We can use this integer and float to do the mathematical calculations.

To know more about calculations read here.

Understanding Data Types in PHP, there are different types of data types in PHP. Previously we have discussed three types of data types in variables.

These are the available data types in PHP

  • String
  • Integer
  • Float
  • Boolean
  • Array
  • Object
  • NULL
  • Resource
Vivek Vengala

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: