Explain about Type Juggling in PHP?

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


Please Help Members By Posting Answers For Below Questions

What is string and its function?

511


Explain array_uintersect()?

582


What are the advantages of php mysql?

514


How many days will it take to learn php?

527


Which function parses an English textual date or time into Unix timestamp in PHP.

563






Write a program in php to print a table of a number?

502


What is a php array?

491


How to use http headers inside php?

560


How to pass an argument to a function?

547


Can you use both this () and super () in a constructor?

529


What is the difference between html and php?

537


What is chrome logger?

550


How do I display php errors?

509


What is a helper function?

537


How can you declare the array in php?

517