Rabu, 21 Agustus 2013

PHP Variable String and Number

PHP has 8 type data of Variable: Boolean (True - False), Integer, Floating
point(decimal), String, Array, Object, Resource, and Null.

In this page i want to explain about using Variable with String in PHP:

There some rule for writing Variable in PHP:

- Writing PHP variable begins with '$' (dollar) character.
- When it included with 2 words, dont input  between both, you can use '_'
(underscore) or combine that 2 words.
- The Character must letter or underscore after '$', cant use Number or Symbol.
- Variable in PHP is Case-sensitive.

Example: $variableName
         $variable_Name
         $variableName with $Variablename is Different.

When we want to fill and show the values of a Variable where the type data is
"String", it need ';' for ending. And if we want include words inside the
command viewer we must use " (double quote).

Example: echo $variableName;
         print $variableName;
         echo "Hi, $variableName";

Here Example for writing Variable with String type data:

< ?php
$fullName = " Bagus Rizaldy S";
echo "My Full Name is$fullName";
echo "My Full Name is".$fullName";
?>

the output will be appear like this:

so, the explanation is we call the contents of the Variable, when we want to combine the Variable and String we must put "." between it. And then try to Number or Numeric: < ?php $number1 = 2; $number2 = "3"; $number3 = "4four"; echo "$number1*$number2"; echo $number1*$number2; echo $number1+$number3; ?> the output will be appear like this:
so, the explanation is see on first output it appear 2*3, why it is not calculate? becuse it use quotes so it detected as string, only appearing and not calculate it, so if you want to make calculate Number or Numerical dont put any quotes like at operaion number 2 when the output 6, so if we didnt put qoutes the letter wont to detect like variable $number3.

0 comments:

Posting Komentar