PHP/Language Basics/Variable Type — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 10:05, 26 мая 2010
Changing the Type of a Variable with settype()
<source lang="html4strict">
<html>
<head>
<title>Changing the type of a variable with settype()</title>
</head>
<body>
<?php
$undecided = 3.14;
print gettype( $undecided );
print " -- $undecided
";
settype( $undecided, string );
print gettype( $undecided );
print " -- $undecided
";
settype( $undecided, integer );
print gettype( $undecided );
print " -- $undecided
";
settype( $undecided, double );
print gettype( $undecided );
print " -- $undecided
";
settype( $undecided, boolean );
print gettype( $undecided );
print " -- $undecided
";
?>
</body> </html>
</source>
gettype() and settype()
<source lang="html4strict">
<html> <head>
<title>Gettype() and Settype() Usage</title>
</head> <body> <?php
$my_double = 100; $my_string = 1; print("\$my_double"s data type is... (" . gettype($my_double) .")
"); print("\$my_string"s data type is... (" . gettype($my_string) .")
"); settype($my_string, "string"); settype($my_double, "double"); print("\$my_double"s data type is... (" . gettype($my_double) .")
"); print("\$my_string"s data type is... (" . gettype($my_string) .")
");
?> </body> </html>
</source>
Testing the Type of a Variable
<source lang="html4strict">
<html>
<head>
<title>Testing the type of a variable</title>
</head>
<body>
<?php
$testing = 5;
print gettype( $testing ); // integer
print "
";
$testing = "five";
print gettype( $testing ); // string
print("
");
$testing = 5.0;
print gettype( $testing ); // double
print("
");
$testing = true;
print gettype( $testing ); // boolean
print "
";
?>
</body>
</html>
</source>