PHP Internet Development: PHP Variables

PHP Internet Development: PHP Variables

Whilst working with any language we make use of variables. Variables are utilized to retailer values ​​and reuse them in our code. We use distinct forms of variables in our code this sort of as strings (text), integers (quantities), floats (decimal numbers), boolean (correct or bogus) and objects. In PHP we can make use of variable although composing scripts. In this lesson we&#39re going to go over PHP variables.

What is a variable?

A variable is a suggest to retail store values ​​such as strings, integers or decimals so we can simply reuse these values ​​in our code. For instance, we can keep a string benefit these kinds of as “I Really like PHP” or an integer worth of 100 into a variable.

PHP Variable Syntax

$ var_name = price Defining Variable in PHP?

In this article is an example of how to declare a variable in PHP.

php $ var_name = "I Love PHP" ?> Some critical details to notice :

– Try to remember to put the $ indication in entrance of variables when declaring variables in PHP.

– Variable names will have to start out with letters or underscore.

– Variables can not include things like figures except letters, numbers or underscore.

PHP variable varieties?

In contrast to Java or C ++, PHP does not care about primitive forms. Any variable, possibly a string, an integer or a float is declared the exact same way. PHP converts the sorts in the code by itself. Below&#39s what I necessarily mean.

php // a string variable $ var_name = "I Love PHP" // an integer variable $ var_name = 100 // an float variable $ var_name = 100.00?> PHP Variable type juggling

Like talked about earlier mentioned, PHP does not require variables to declared using primitive varieties. Consequently, juggling concerning two types does not need use of any unique operate. We can basically do matters like …

php // string var $ var = 0 // var is now float $ var + = 2.5 // var is now integer $ var + = 2 // var is now string $ var. = "is the total" echo $ var ?> Concatenating variables in PHP?

In PHP we can be part of two variables by making use of the dot &#39.&#39 operator.

php $ var1 = "I Love PHP" $ var2 = "and Java" // prints "I Love PHP and Java" echo $ var1. $ var2 $ var1 = 1 $ var2 = 2 // prints "12" echo $ var1. $ var2 ?>

So there you have it, a swift and easy variable lesson in PHP. You can see much more examples of PHP variables at or go to Find out PHP for more tutorials.

Have enjoyable coding!

Resource by Gee Singh

Leave a Comment

Your email address will not be published. Required fields are marked *