Sunday 12 October 2008

valid n invalid Variabels

Valid variabels

a : Single-letter variables are good for temporary purposes, such as loop counters.

firstName : Variables that look like words help make your scripts easier to understand.

_1 : Traditionally, variables that begin with an underscore have special meaning to the local namespace.


inValid variabels

1 : The first character following the dollar sign may not be a number.

7Lucky : The first character following the dollar sign may not be a number. Use Lucky7 instead.

~password : ~ is not an alpha character and may not be used in variable names.

Last!Visit : ! is not an alpha character and may not be used in variable names. Use LastVisit or last_visit instead.

Compute-Mean : - is not an alpha character and may not be used in variable names. Use Compute_Mean instead.



The equal sign (=) is used to set the value of a variable. This is called the assignment operator. On the left side of the assignment operator is a variable that will receive a value. On the right side is an expression, which could be a simple string constant or a complex combination of operators, variables, and constants. The simplest form of assignment is from a constant expression. This could be a number or a string surrounded by quotes.

Sample of Variables Assignments
String Constants Integer Constants Double Constants

$myString = "leon"; $myInteger = 1; $myDouble = 123.456;
$myString = "\n"; $myInteger = -256; $myDouble = -98.76e5;



Most compiled languages, such as C or C++, require you to declare every variable along with the type of value that it will contain, and they require every code piece to state in advance what kind of values it is designed to work with. Most interpreted languages, such as PHP, allow variables to store any type of value and allow code units to work with any type of value. PHP doesn't even require you to explicitly declare a variable before you use it. Instead, the first time you assign a variable with some value, it is created. This simplifies development and helps you produce and maintain working programs more quickly. It also can lead to bugs when you use a variable before initializing it.

Variables in PHP don't have designated types. Instead, the type of the variable is considered to be the type of the value that it contains. The type of value that variables contain may be changed at any time. For example, assigning an integer to a variable that previously held a string converts the variable to an integer. This is in contrast to C, where each variable has a designated type. Assigning a value to a variable of a different type will make C attempt to convert the value so that it fits the variable.

How to use variabel

//create variable
$result = 2 + 5;

//create another variable
$doubleResult = $result * 2.001;

//print the second variable
print($doubleResult);
?>

As mentioned earlier, double-quoted strings and HERE docs may contain embedded variables. You may write a variable inside a string surrounded by double quotes, and its value appears in its place. This even works with arrays and objects. Listing below is an example of this technique. Notice that the name variable appears within a print statement between double quotes.

$name = "Zeev";

//Greet Zeev
print("Hello, $name!\n");

//Greet Zeev again
print <<< EOD
Hello again, $name!
How is it going?
EOD;
?>

Layakkah kita?!

Pada saat wafatnya Sulaiman-khalifah sebelum Umar bin Abdul Aziiz-, ada seorang lelaki datang menemui Umar bin Abdul Aziiz. Lelaki itu berkata, "Relalah dengan ketentuan Allah,serahkanlah semua padaNya, dan harapkanlah apa yang ada di sisiNya. Sesungguhnya, di sisi Allah ada kebaikan abadi dan ada ganti dari musibah. Lihatlah kematian yang kau takutkan pada Sulaiman maka takutkanlah pada dirimu". Lelaki itu lalu beranjak pergi.

Umar berteriak,"Kembalikan dia padaku. Aku perlu bicara dengannya." Begitu lelaki itu datang kembali, Umar berkata "untuk apa kau katakan semua itu padaku?" Lelaki itu menjawab,"Jika kamu percaya pada ku, aku akan memberitahu kamu." Umar menukas, "Baik, aku percaya padamu."

Lelaki itu berkata, "Di Madinah, aku melihat kamu berpenampilan mewah dengan sombongnya, kau ulurkan sarungmu, kau uraikan rambutmu, kau tebarkan wewangian berlebihan sehingga aku takjub bagaimana Allah membiarkanmu untuk tetap untuk menjadi penghuni bumiNya. Ketika mengetahui keadaanmu itu, sudah semestinya aku memberikan belasungkawa dan memenuhi hakmu."

Umar lantas berpesan,"Saudaraku, jika kamu tinggal bersama kami di bumi kami, berjanjilah mengingatkan kami, dan jika kamu keluar, semoga dilindungi Allah."