Page 1 of 1

teting types of variables(outputnnot showing)

Posted: Wed Jun 16, 2010 4:38 pm
by mattg77
Hi just learning php from samms teach yourself, typed in code from book and when tested output not showing. Apache is running and php is working as have done test, using php page in dreamweaver. Can anyone help this is code below. Thanks

Code: Select all

<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php 
$testing; // declare without assigning
echo "is null? ".is_null($testing); // checks if null
echo "<br/>';
$testing = 5;
echo "is a integer? ".is _int($testing); // checks if integer
echo "<br/>";
$testing = "five"; 
echo "is a string? ".is_string($testing); // checks if string
echo "<br/>";
$testing = 5.024;
echo "is a double? ".is_double($testing); // checks if double
echo "<br/>"; 
$testing = true;
echo "is boolean? ".is_bool($testing); // checks if boolean
echo "<br/>";
$testing = array('apple', 'orange', 'pear,');
echo "is an array? ".is_array$($testing); // checks if array
echo "<br/>";
echo "is numeric? ".is_numeric($testing); // checks if numeric
echo "<br/>";
echo "is a resource? ".is_resoure($testing); // checks if is a resource
echo "<br/>";
echo "is an array? ".is_array($testing); // checks if is an array
echo "<br/>";
?>
</body>
</html>

Re: teting types of variables(outputnnot showing)

Posted: Wed Jun 16, 2010 5:14 pm
by hypedupdawg
I don't know what output you were expecting - but it won't work. Functions like "is_int" return a boolean value - that is, 1 or 0. To utilise these values, use an "if...else" statement. For example, like this:

Code: Select all

$testing = "Hello World!"

if(is_string($testing)==1){ //If the function is_string returns true
echo "Is a string."; //echo this
}else{
echo "Is not a string."; //otherwise, echo this
}
You can also say the opposite, using the "!=" operator: this means "is not equal to". I advise you to read this page on the "if" function, and this page on operators (especially the comparison operators). Have fun!