Variables:
Variables are used to hold different types of data. Some data types are Integer, character, float, double, string etc..
PHP Variable Declaration :
Assigning Values to Variables:
There are two ways to assign values to variables,they are
Example:
Output:
Variables are used to hold different types of data. Some data types are Integer, character, float, double, string etc..
PHP Variable Declaration :
- Variable have to begin with a dollar sign ($).
- After the $ symbol, variable names can be begin with a letter or a Under score(_). Variable names cannot be started with a number in php.
- Variable names are case sensitive. That is $firstname is a completely different variable than $FirstName.
PHP Data Types :
Segment
|
Type
|
Description
|
Scalar types | Boolean | Logical TRUE or FALSE |
Integer | Whole numbers: e.g 1,2,3... | |
Float (double) | Numbers with decimal notations e.g., 12.56 or 345.456 | |
String | Characters, letters, or numbers (usually defined within double quotes): e.g., “Hello there” or “123AsR” |
|
Compound types | Array | A collection of keys with their values, arrays can hold other arrays (multidimensional); |
Object | The basics for class definitions and object-oriented programming; | |
Special types | Null | Defines a variable with no value; the variable exists, but contains nothing (not an empty string, not the value 0, nothing) |
Resource | Stores a reference to functions, databases, files, or other resources outside of PHP |
Assigning Values to Variables:
There are two ways to assign values to variables,they are
- by value
- by reference
By Value:
Syntax:
- $variablename = value;
Example:
- $a = 12;
- $b = "StudentsBlog100";
By reference:
Syntax:
- $firstname = "Peter"; // assigned by value
- $fname = &$firstname; // $firstname is assigned to $fname by reference.
Example:
Hello StudentsBlog100!
5
10.5
No comments:
Post a Comment