Jump to content

Recommended Posts

I need to create a php script to....

declare and assign 3 integer variables, one for house number one for zip code and one for the area code. Use echo() statements to print each variable along with gettype() to assure each variable is of data type integer.

 

 

I appreciate any help as I have almost no experience with php.

 

Reply here or Jpower24@hotmail.com

Link to comment
https://forums.phpfreaks.com/topic/38192-solved-help-needed-beginner-here/
Share on other sites

 

<?php
$house_addr = gettype(1234);
$zip = gettype(12345);
$area_code = gettype(123);
if($house_addr != "integer"){
# tell users wrong datatype
}else{
#run your house_addr code
}
if($zip != "integer"){
# tell users wrong datatype
}else{
#run your zip code
}if($area_code != "integer"){
# tell users wrong datatype
}else{
#run area_code code
}
?>

If you use that code provided by The Little Guy then nothing will come up as you are not echo'ing anything. To make it echo something just add echo 'whatever' where the comments are in the if/else statements code blocks. A code block is defined in between  the curly braces { and }

Use double quotes instead if you want to echo variables values in a string.

 

If you use single quotes PHP will treat variables as normal text (as-is).

 

So use

echo "The address is $house_addr";

instead or you can use concatenation (See The Little Guy's example above in his post)

alright so now I have this.

 

<?php
$house_addr = gettype(1234);
$zip = gettype(12345);
$area_code = gettype(123);
if($house_addr != "integer"){
echo "The number of the house is 

$house_addr";
}
if($zip != "integer")
{
echo "The zip code is $zip";
}
if($area_code != "integer"){
echo "The area code is $area_code";
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.