teting types of variables(outputnnot showing)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mattg77
Forum Newbie
Posts: 1
Joined: Wed Jun 16, 2010 3:24 pm

teting types of variables(outputnnot showing)

Post 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>
Last edited by Benjamin on Wed Jun 16, 2010 6:47 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
hypedupdawg
Forum Commoner
Posts: 74
Joined: Sat Apr 10, 2010 5:21 am

Re: teting types of variables(outputnnot showing)

Post 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!
Post Reply