Answer Posted / rekha_sri
In PHP there is no need to declare the variable with
explicit type declaration. Variable type is specify by the
context.
For example, if we assign the integer value into variable,it
will be integer variable and if we assign the string value
into variable it will be string.
Example:
--------
<?php
$a=10;
$b="string";
echo "$a"; // 10
echo "$b"; // String
?>
If we want to force the variable type into different type we
can do the type casting.
Type casting example:
---------------------
<?php
$one = 10; // $one is an integer
$two = (boolean) $one; // $two is a boolean
?>
In PHP we are having function called settype() for setting
the particular variable type.
settype() example:
------------------
<?php
$first = "10rose"; // string
$second = true; // boolean
settype($first, "integer"); // $first is now 10 (integer)
settype($second, "string"); // $second is now "1" (string)
?>
| Is This Answer Correct ? | 8 Yes | 0 No |
Post New Answer View All Answers
Explain difference between urlencode and urldecode?
Declare a new variable in php equal to the number 3;
What are string functions?
What does the unset() function means?
How to avoid the undefined index error?
What is difference between required and require_once in php?
What are the difference between abstract class and interface in oops?
What are the advantages of stored procedures?
How to calculate the length of a string?
How to create a text file in PHP?
Why ide is recommended for use while programming with php?
What is reference variable php?
Which will check if a function exists?
Is wordpress a php framework?
Which function is used in php to count the total number of rows returned by any query?