w3reference home
PHP Tutorial


Bookmark and Share

PHP Variables

What are variables?
Variables are names that store values like strings or numbers. Their values can change at any point in the whole program. Since the value is variable, they are known as variables.

Declaring Variables
Most programming languages require variables to be declared. This is done to ensure what data type it is and hence, what type of data it can store. Each programming language has its own set of data types. In case of PHP, the variables do not have to be declared. PHP automatically converts the variable to the correct data type, depending on how they are set. Hence, PHP is known as a loosely typed language. A strongly typed language requires you to declare the variables in the beginning of the program. Assigning values to variables in PHP
Variable names begin with a dollar sign ($). Lets have a look at the following statements:

$worda = "gnulamp";
$wordb = "php tutorial";
$website_url = "http://www.gnulamp.com";
$word="$worda $wordb";
$num1 = 10;
$num2 = 20;
$sum = $num1 + $num2;
Some rules to remember
  • A variable name must start with a letter or an underscore (_).
  • A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ ).
  • A variable name should not contain spaces. If needed, underscores should be used.
  • Variabe names are case sensitive.
  • String constants are enclosed in quotes (").
  • Numeric values are assigned as it is.
Code Validator
Learn FTP
Color finder
Link Checker
Free web designs
Coming soon!
Interview Questions...
'w3reference : Learn by examples ... Advanced to beginner's tutorials ...'
Ajax: AJAX tutorial1 | Apache: Apache HTTP Server | Restarting Apache | CSS: CSS Border | CSS Syntax | CSS Selector | CSS Comment | CVS: CVS Release | CVS Login | CVS Logout | CVS Annotate | Databases: Rolap Tutorial | OLAP Tutorial | OLTP Tutorial | data warehousing | Expect: HTML: html | Linux: Dot (.) conf files | Linux Mount Point | Linux Filesystem | SSH Tutorial | Linux Commands: cal | cat | cfdisk | chroot | MySQL: MySQL Commands | PHP: PHP Basics | PHP Variables | PHP Output (echo/print) | PHP String Concat | PL/SQL: PL/SQL Data Types | PL/SQL Control Structures | PL/SQL File Extensions | PL/SQL DBMS_OUTPUT package | Python: My first Python program | Shell: Starting Bash | Bash Redirection | Bash Pipes | Bash Variables | SQL: SQL Transactions | SQL Constraints | SQL Drop | SQL Union & Union All | SVN: svn architecture | SVN Repository | SVN Import | SVN Checkout | Tech: soap | Web Designing: Web Hosting | HTML/XHTML/CSS code validator | Learn FTP | Search Engine Optimization Tips | www: XML: XML vs HTML | XML Syntax | XML Tags, Elements and Attributes | XML Namespaces |
Sitemap | Disclaim | Privacy Policy | Contact | ©2007-2009 w3reference.com All Rights Reserved.