0% found this document useful (0 votes)
3 views3 pages

PHP Practice 2

The document contains three PHP programs demonstrating variable type testing, changing types using settype(), and casting variables. Each program illustrates how to declare variables, check their types, and convert them between different types such as integer, string, double, and boolean. The output of each operation is displayed, showing the type and value of the variables at each step.

Uploaded by

laxmibengeri2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

PHP Practice 2

The document contains three PHP programs demonstrating variable type testing, changing types using settype(), and casting variables. Each program illustrates how to declare variables, check their types, and convert them between different types such as integer, string, double, and boolean. The output of each operation is displayed, showing the type and value of the variables at each step.

Uploaded by

laxmibengeri2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

//Program 15 : To test the type of variable

<html>

<head>

<title>Testing the type of a variable</title>

</head>

<body>

<?php

$testing; // declare without assigning

echo gettype($testing); // null

echo "<br>";

$testing = 5;

echo gettype($testing); // integer

echo "<br>";

$testing = "five";

echo gettype($testing); // string

echo "<br>";

$testing = 5.0;

echo gettype($testing); // double

echo "<br>";

$testing = true;

echo gettype($testing); // boolean

echo "<br>";

?>

</body>

</html>
//Program 16: To change the type of variable

<html>

<head>

<title>Changing the type of a variable with settype()</title>

</head>

<body>

<?php

$undecided = 3.14;

echo gettype($undecided); // double

echo " is $undecided<br>"; // 3.14

settype($undecided, 'string');

echo gettype($undecided); // string

echo " is $undecided<br>"; // 3.14

settype($undecided, 'integer');

echo gettype($undecided); // integer

echo " is $undecided<br>"; // 3

settype($undecided, 'double');

echo gettype($undecided); // double

echo " is $undecided<br>"; // 3

settype($undecided, 'boolean');

echo gettype($undecided); // boolean

echo " is $undecided<br>"; // 1

?>

</body>

</html>
//Program 17: Casting

<html>

<head>

<title>Casting a variable</title>

</head>

<body>

<?php

$undecided = 3.14;

$holder = (double) $undecided;

echo gettype($holder) ; // double

echo " is $holder<br>"; // 3.14

$holder = (string) $undecided;

echo gettype($holder); // string

echo " is $holder<br>"; // 3.14

$holder = (integer) $undecided;

echo gettype($holder); // integer

echo " is $holder<br>"; // 3

$holder = (double) $undecided;

echo gettype($holder); // double

echo " is $holder<br>"; // 3.14

$holder = (boolean) $undecided;

echo gettype($holder); // boolean

echo " is $holder<br>"; // 1

echo "<hr>";

echo "original variable type: ";

echo gettype($undecided); // double

?>

</body>

</html>

You might also like