2014. szeptember 10., szerda

PHP alap típusok, gettype( )

Típus nélkül is adhatunk értékeket a változóknak, akkor majd a PHP ad nekik típust!

Az értékadás a következő:
$testing = 5;

Egy típustesztelés:

<!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.1 Testing the Type of a Variable</title>
</head>
<body>
<div>
<?php
$testing; // declare without assigning
print gettype( $testing ); // NULL
print "<br />";
$testing = 5;
print gettype( $testing ); // integer
print "<br />";
$testing = "five";
print gettype( $testing ); // string
print "<br />";
$testing = 5.0;
print gettype( $testing ); // double
print "<br />";
$testing = true;
print gettype( $testing ); // boolean
print "<br />";
?>
</div>
</body>
</html>


Eredmény:

Notice: Undefined variable: testing in E:\STY PHP in 24 Hours\Hour 04\listing4.1.php on line 12 NULL
integer
string
double
boolean

Nincsenek megjegyzések:

Megjegyzés küldése