Variables used as a temporary data storage. The data stored in the variable will be lost after the program finishes execution. For the permanent storage of data, we can store data in a database or on disk. Please refer to the Access Database to explore the use of databases, and access files and folders for data storage in the filesystem. Variables in PHP start with a $ sign, to be able to use variables, there are two steps that must be done, the declaration and initialization.Declaration of VariablesDeclaration of a variable can be called also introduce or register variables into the program. In PHP, the variable declaration is often combined with initialization. Variables in PHP is expressed with the prefix $. Example:$ Name$ Address$ AmountThere are some rules to be followed in respect of the variable name, include the following:
Variable preceded by a $
The first character after the $ sign must be a letter or an underscore (_)
The next character should be letters, numbers, or underscores.Variable InitializationInitialization of variables is to fill the value for the first time into a variable. Example of initializing variables initialization is as follows:$ Name = "Widi Mawardi";$ Address = "Mother Road Cimahi Ganirah No. D-252 London";$ Number = 100;Data Types in PHPIn other programming languages such as Delphi, Visual Basic, Java, etc. there are different types of data that must be declared, for example, integer (an integer), float (fractions), char (character numbers and letters), string (a collection of letters or words), and various other data types. PHP knows two simple data types, namely, numerical and literal. Plus the two data types are not simple, namely array and object. Numeric Types in PHP used to store integers.PHP is able to store integer data with a range from -2 billion to +2 billion. Examples of integers: 3, 7, 20. In addition, numeric type is also used to store fractions. Literal types used to store the data in the form of a collection of letters, words, and numbers. Boolean type, known in other programs, not in PHP. To test the correct one (true false), we use the available data types. FALSE may be replaced by the integer 0, 0.0 or double the empty string, which is "". In addition to that value, all are considered TRUE.Variables can be used to store various types of data. For example, numerical data that can be operated in mathematics. Example:
$ Number = 10;$ Price = 2000;$ Total = $ amount * $ price;/ / The above variables, the variable will store the payment of 20 000While the non-numeric data (also known as literal data) can not be operated in mathematics. Example:
$ Name = "Widi Mawardi";$ Address = "Mother Road Cimahi Ganirah No. D-252 London";$ Description = $ name + $ address;/ / The above variables, the variable will store the description of a combination of two variables, namely the "Mother Road Mawardi Widi Ganirah No. 252-D Cimahi Bandung".In general, literal data marked with partner executives sign the "text", while the numerical data are not surrounded by quotation marks. But usually PHP will automatically convert data types as needed. Example:
$ Path = "Ganirah Mother Road";$ No = 252D;$ Rt = 5;$ Postcode = 40 531;$ Literal = $ path + $ no;/ / The literal variable will store the "Mother Road Ganirah 252D".$ Numeric = $ rt + $ zipcode;/ / The numeric variable will store the "40 531".$ Hasilaneh = $ rt + $ no;/ / Note, this automatic conversion sometimes is not runningproperly. It can be seen from the variable that will hasilanehstore the value 257. PHP takes the numerical value of the variable rt, ie5, then add the contents of the variable no. Resultthe end is 5 + 252, ie 257Passing Variable In PHPPassing variables can be passed on or next to a web page that is accessed by users. Passing Variable There are several techniques, including:
Through the URL
Through the Form
Through a cookie
sample code in a PHP variable
</font> <font class="hps">Exercise</font> <font class="hps">Variables</font> <font class="hps atn"><</font>/ <font class="hps">title></font><br> <font class="hps atn"><</font>/ <font class="hps">head></font><br> <font class="hps"><body></font> <font class="hps">Ngoding</font> <font class="hps">with</font> <font class="hps">PHP</font>. <font class="hps"><br></font><br> <font class="hps atn"><</font>? <font class="hps">php</font><br> <font class="hps">$</font> <font class="hps">name</font> <font class="hps">=</font> <font class="hps atn">"</font>Rudini";<br> <font class="hps">printf</font> <font class="hps atn">(</font><font class="hps atn">"</font>Hi,% <font class="hps">s</font>", <font class="hps">$</font> <font class="hps">name</font>);<br> <font class="hps">?</font>><br> <font class="hps atn"><</font>/ <font class="hps">body></font><br> <font class="hps atn"><</font>/ <font class="hps">html</font>></font><b><font class="long_text" id="result_box" lang="en"><font title="Melalui Cookie"><font color="#00ff00"> </font></font></font></b></p></div>
0 comments:
Posting Komentar