<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Listing 4.3 Casting a Variable</title>
</head>
<body>
<div>
<?php
$undecided = 3.14;
$holder = ( double ) $undecided;
print gettype( $holder ) ; // double
print " -- $holder<br />"; // 3.14
$holder = ( string ) $undecided;
print gettype( $holder ); // string
print " -- $holder<br />"; // 3.14
$holder = ( int ) $undecided;
print gettype( $holder ); // integer
print " -- $holder<br />"; // 3
$holder = ( double ) $undecided;
print gettype( $holder ); // double
print " -- $holder<br />"; // 3.14
$holder = ( bool ) $undecided;
print gettype( $holder ); // boolean
print " -- $holder<br />"; // 1
?>
</div>
</body>
</html>
Eredmény:
double -- 3.14
string -- 3.14
integer -- 3
double -- 3.14
boolean -- 1
Nincsenek megjegyzések:
Megjegyzés küldése