Mga Pahina

Linggo, Enero 23, 2011

PHP Variables

In this PHP programming language tutorial we will look at variables. A variable is used to store information or values in, like text-strings, numbers or arrays. As long as you don’t remove the value in a variable then you can use the variable (thus the value) over and over again.

PHP Variable Declaration

All variables in PHP begin with the $ sign. A common mistake of new PHP programmers is to forget the $ sign before a variable, so don’t forget it!
Let’s look at a variable declaration in PHP:
<?php
$sample = 100;
$sample2 = "Hello World!";
?>
First we declare the variables e.g. ($sample is 100  and $sample2 is Hello World ).
Important for using variables, The code must have dollar sign($) in variables when entering a code and equals  when assigning a data e.g. a number or name
Don't forget a semi colon when it ends your variables and then the apostrophe must apply in data for names that should be execute in page.
Note:  for people that have written programs in other language, such as C/C++ for instance, you don’t have to determine the data type of the variable (example in C Language: int my_var = 20; .) The PHP language is a loosely typed language, which means that PHP automatically converts the variable to the correct data type, depending on its value. The C/C++ languages are strongly typed programming languages.

Variable Rules

You have to follow some rules when naming a variable:
  • A variable name cannot contain spaces.
  • 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 _ ).
Reference: codingunit.com

1 komento:

  1. Hello,
    Great blog i like it
    Magento is flexible and allows us to modify existing features or add in new ones. Integration of other platform is easy. There are tools which allow you to import products, customers and other information from other carts such as OSCommerce and X-Cart.

    TumugonBurahin