Jump to content

[SOLVED] Help needed, beginner here.


Jpower24

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 [email protected]

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";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.