PHP static variable | what are variables in php? | php variables

Share:

PHP static variable | what are variables in php?

PHP static variable
PHP static variable

Variables are the basic structure of a programming language. Memory is a place where we save our data which we need for program. We save temporary these data these are data container which value change time by time. In this article I will discuss PHP static variable.
What I will cover in this article why we need variable in php language. How to make php variable? What are the rules of making variable in php programming language? I will take example of variable declaration. Assign value to php variables.  Some example of variable in php script, and explanation of php script. Also see How to comment in PHP 

Why we need variable in PHP programming?

Consider if I am going to develop a program in PHP which will sum two numbers, if I don’t use variable then I will do like this.
Echo (5 + 2 ) ;
Its answer you know that it will be 7
Now I have more two numbers 3 and 6 or 9 and 20 and more numbers.
What will we do?  Will we change our code for each number change?
See the example first I will do but these will not effective for long code
Echo ( 3 +  6 ) ;
Echo ( 20 +  9 ) ;
In these cases we need variable to solve these problems.

Second example: 

I want to develop a program that user will input his name and when click on the button then it will shows a well come message like this  ( Well come Saeed Developer to our website )  at user name maybe change by the user name for example if it’s not a saeed developer then it maybe ALI or any other name. Here you need variable to solve this problem. It is called PHP static variable

How to make PHP variable?  Static variable in php

In PHP programming language to make a variable is very easy task.
First of all we put $ sign then give a variable name.
Variable name maybe on letters small or capital a-z A- Z numbers 0-9 and _ underscore means you cannot use space in variable name in PHP.
Your variable name may start from letters or _ underscore
Variable should not exceed 30 character limits.

Examples of variables  Declaration | php declare variable without value

$a;
$a_variable;
$_1234;
It means that we make space for save some value.
When we make space it’s called variable declaration. After this step we can assign value to our variable.

Assign value to variable types of variables in php

$a = “Saeed”;
= is assignment operator it assigns value to variable whatever have in front of the variable.

Example of variable use php variable in string

< ? php
$num_1 = 50;
$num_2 = 100;
$sum = $num_1 + $num_2;
Echo “sum is: “. $sum;
? >
The output of the program will be
Sum is:  150

More understanding about this PHP script php variable in string

First you can see I make two variables $num_1 and $num_2  
I assign values to these variables
After assigning the value to these $num_1 and $num_2  variables
At second last step I make a new variable $sum and assign the both $sum_1 and $sum_2 variable with addition sign between them. This will add these two variable and assign the total of these variables to $sum variable as a result.
$sum = $num_1 + $num_2  these will add both first variables and assign value to $sum variable
At the end I print the $sum with echo statement.  In this echo statement you are seeing a dot . what does this do? When we combine two strings then we put dot . in these two strings. It is called concatenation. In this statement we use these two strings. “sum is:” and $sum variable connected and print it. And as a result we see
Sum is:  150

Final words

I hope I cover this topic about what are the variables in php programming language. I tried my best to provide you as simple knowledge as I can but if you even don’t understand better or having something to clear your concept then feel free to ask me questions I will provide you best solutions of your problems. Static variable in php

Give me feedback

Please provide me feedback I will surely read your comment what you want to know about and if your concept are not even clear I will give you more details about the topic you are facing problem. I will discuss with more details that clear your concepts.PHP static variable and PHP static variable and PHP static variable PHP static variable PHP static variable PHP static variable PHP static variable PHP static variable 


No comments