Static Variable | Static Variable in Php | Static Variable Example

Share:
Static Variable | Static Variable in Php | Static Variable Example with details


Static Variable | Static Variable in Php | Static Variable Example
Static Variable | Static Variable in Php | Static Variable Example 

Variables are the basic structure of a programming language. So in this article, I will discuss with details on topics of Static Variable, Static Variable in Php, Static Variable Example, and much more.
Memory is a place where we save the data which we need for the program. We save temporary data these are data containers that value change time by time. In this article, I will discuss the PHP static variable. What I will cover in this article is why we need variables in the PHP language. How to make PHP variable? What are the rules of making variables in the PHP programming language? I will take the example of variable declaration. Assign the value to PHP variables.  Some examples of variables in the PHP script, and explanation of PHP script. Also, see How to comment in PHP 

Why do we need Static Variable programming?

Consider if I am going to develop a program in PHP that will sum two numbers, if I don’t use variables 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 be effective for long code
Echo ( 3 +  6 ) ;
Echo ( 20 +  9 ) ;
In these cases, we need variables 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 create Static Variable in Php?  Static variable in php

In the PHP programming language to make a variable is a very easy task.
First of all we put $ sign then give a variable name.
The variable name may be 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
The variable should not exceed 30 character limits.

Examples of Static Variable Example  Declaration | PHP declare a 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 Static Variable in Php

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

Static Variable Example 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 the 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 have 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 about what you want to know about and if your concept is not even clear I will give you more details about the topic you are facing a problem with. 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

Note: Only a member of this blog may post a comment.