Thursday, 13 February 2014

Variables in php

php variables
Variables
This tutorial is for variables. If you have worked with any other programming language you know what are variables for and what they will do.Values are assigned to variables and variables are of different types.Now in this tutorials i am going to show you how to declare variables by assigning values to standard structure and then variables are echoed out on the browser.So, Usually in programming languages such as JavaScript or for any other language like it we have to use keywords,for example in java we use “var” like var example.





<?php

var name = 'value';

?>



In php we don’t need any keywords to define anything only we need to assign it with “$” dollar sign notation and afterwards we can assign “_” sign or characters or strings or numeric characters also. Assigning can be done in upper-case and lower-case both.
Code for Variables(Screenshot1) :-

Variables
Code For Variables Screenshot1


<?php

echo $text = 'Hello World.';

echo $number = 100;

?>



output (Screenshot2) :-

Code for Variables
Screenshot2


In Screenshot1 you can see codes for string.I have used sign ” notation for numeric value and i am not using any notation but only semi colon “;” . Semi colon “;” is a separator. Echo statementecho’s out the variables.We can assign any value to variables such as floating values, Boolean values,etc., but this we will see later on in if statements.

Code for variables different way (Screenshot3) :-

Variables in php
Code for Different types for variables Screenshot3


<?php

$text = 'Hello World.';

$number = 100;

 echo $text;

?>


Output (Screenshot4) :-

code for variables in php
Variables Screenshot4

It will only echo variable $text contain because we only echoing $text variable Code for variables different way second example (Screenshot5):-

Screenshot5


<?php

$text = 'Hello world.";

$number = 100;

echo $number;

?>

Output(Screenshot6) :-

Variables string
Screenshot6


It will echo out the content of variable $number because we are echoing variable $number. Programming languages are used todeclare different data’s, for example you want to take users age or take users name or anything you need to declare,so either you will store it as string data or you will store it as numerical data like integers (similarly for floats),which is somewhat tedious ! But, I would like to tell you an important aspect of php , that you don’t need to think about what data you are storing, you just simply need to assign “$” Sign in the prefix of variable name following with equal to and the variable value. Declaration of variables in php is quite easy.



No comments:

Post a Comment

Thanks For Comment Will get you Soon..

About Me

Welcome to Extra Tutorials! My name is Mohammed and I am the 22 year writer, website developer, and photographer behind the blog. Thanks for visiting! Tutorials Jackpot… In addition to Developer, I love to develop websites and I love to write. Starting a php Blog was inevitable for me. What began as a simple way to share all of my Tutorials with friends and family has developed into my Part time job.

Mohammed Padela

WHAT IS PHP PROGRAMMING

WHAT IS PHP PROGRAMMING
WHAT IS PHP PROGRAMMING

Follow Us

Popular Posts

Designed ByBlogger Templates