LEARNING PHP AND MYSQL (2015)
Variables are used to store values like strings numbers etc. When a variable is declared, it can be used again and again in your script. Symbol used to represent PHP variables is “$ “.
$ var _ name = value;
There is no need to specify in PHP that the variable use belong to which data type. PHP converts the variable into correct data type. A variable name can also contain alpha numerical characters but it should not contain space.
$name = ‘Raj’;
$year born = 1977;
$current year = 2015;
$age = $current year - $year born;
Print (“$name is $age years old”)
The work environment that is been used by you is been accessed by the PHP script. Such variables are stored in a special hash data like $_ENV and $_SERVER. These variables can be used only one two in count at a time.
<HEAD><TITLE>Example 2</TITLE> </HEAD>
print(“you are using $_SERVER[HTTP_SERVER_AGENT]<br>”);
print(“your internet address is $_SERVER[REMOTE_ADDR]<br>”);
Variable from external source
Html forms (GET and POST)
Information from the form when submitted to PHP is automatically made available to the particular script.
<form action = “foo.php” method = “post”>
Name- <input type = “text” name = “username” /><br />
Email- <input type = “text” name= “email” /><br/>
<input type = “submit” name = “submit” value = “submit me!” />
Array is an ordered map actually in PHP .This type of optimization is so that it can have several different uses. Arrays value can be arrays, trees and even multidimensional arrays.
Key => value,
Key a => value2,
Key b => value3,
Array can also be made using a key/value pair combination. These are also considered as associative arrays and hashes. An easy way to compress hash work is to think it as a table.
<? php // create the array (
‘Cambodia’ => ‘Phom Penh’,
‘Lebanon’ => ‘Beirut’,
‘Cuba’ => ‘Habana’,
‘Finland’ => ‘Helsinki’);
Print ($capital [‘Cambodia’]);
Predefined constant of array