Friday 10, February 2012
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    Forum    |    About Us    |    Contact Us

Variables

Variables in PHP are denoted by the "$". To assign the value "Hello World" to the variable $str, you simply call it in your code:

$str = "Hello World";

Strings must be enclosed by quotes, but they can contain variables themselves:

$a = 12;

$string = "The value of a is $a";

// $string = "The Value of a is 12";

PHP variables do not have to be declared ahead of time, nor do they require a type definition. Note that you may get a warning about using undeclared variables if you try to use them before giving them a value (depending on how you set up error reporting in php.ini). For example:

$a = 4;

$c = $a + $b;

// $c = 4, but a warning appears "Warning: Undefined variable..".

Warnings do not stop a script from continuing. If you forgot to add a semicolon at the end of one of the lines, then you would get a Parser error, which prohibits the script from running.

Since PHP variables are not typed, you don't have to worry about performing mathematical equations on the wrong type, as you might in C. For example:

$a = 4;

$b = "5";

$c = $a + $b;

// $c = 9;

PHP also supports boolean variables, which can be assigned either a one or a zero, or the words true or false:

$a = true;

$b = 1;

//$a = $b

$c = false;

$d = 0;

//$c = $d

 

Variable Naming Rules
  1. A variable name must start with a letter or an underscore.
  2. A variable name can only contain alpha-numeric characters and underscores (a-Z, 0-9, and _ )
  3. A variable name should not contain spaces. If a variable name is more than one word, it should be separated with underscore ($my_string), or with capitalization ($myString)

 

 

Comments:

You can include comments in your PHP scripts. Comments are ignored by the Web server, and any comments contained within the PHP code are not sent to a browser. There are three forms of comments:

# Used just like it is used in PERL; comments out the remainder of the line after the # symbol.

// Used just like it is in JavaScript; comments out the remainder of the line after the // symbols.

/* and */— Comments out anything in between the two sets of symbols. This is the same syntax used in C to comment code.

Examples of comments in PHP code:

%

 
     
   
PHP Tutorial
 
  Introduction
Introduction
  Variables
Variables
  Strings
Strings
  Operators
Operators
  If Else Statement
If Else Statement
  Loops
Loops
  Functions
Functions
  Forms
Forms
  Sessions
Sessions
  Cookies
Cookies
  Files
Files
  E-mail
E-mail
  Error Handling
Error Handling
  File Upload
File Upload
  PHP Databases
PHP Databases
  Connecting to a MySQL Database
Connecting to a MySQL Database
  MySQL Data Types
MySQL Data Types
  Inserting Data Into a Table
Inserting Data Into a Table
  Select Statement
Select Statement
  Where Clause
Where Clause
  Order By
Order By
  Update Statement
Update Statement
  Delete From Statement
Delete From Statement
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
  ASP Tutorial
ASP Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download How to Succeed in Online Marketing and Sales Because of Proven Techniques Ebook How to Succeed in Online Marketing and Sales Because of Proven Techniques
   
Download BMA s Marketing Articles Vol I Ebook BMA s Marketing Articles Vol I
   
Download How to Receive Goods FOR FREE Ebook How to Receive Goods FOR FREE
   
Download Structure and Interpretation of Computer Programs  Ebook Structure and Interpretation of Computer Programs
   
Download Creating XPCOM Components  Ebook Creating XPCOM Components
   
 
Studiesinn.com © 2012 All Rights Reserved.
Website Designed & Developed by TechXprtz