Jump to content

Archived

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

CanMan2004

varible using if statement

Recommended Posts

Hi

I want to change my varible, the current code I use is

[code]$name = "Dave Lawson";
print $name;[/code]

I want to put a if statment into the above, the if statement I want to use looks like

[code]if ($hisname >= '1') { print " and "; } else { print "s"; };[/code]

I tried to do

[code]$name = "Dave Lawson" if ($hisname >= '1') { print 's and '; } else { print 's'; };
print $name;[/code]

But that brought nothing but errors.

Can anyone help?

Thanks in advance

Dave

Share this post


Link to post
Share on other sites
Try this:

[code]
$name = "Dave Lawson";

if ($hisname >= '1')
{

print 's and ';

}
else
{

print 's';

}

print $name;
[/code]

Share this post


Link to post
Share on other sites
Assuming that $hisname is greater than or equal to one, the code you've just posted will print...

[color=red]s and Dave Lawson[/color]

Probably not quite what you want...

Regards
Huggie

Share this post


Link to post
Share on other sites
If $hisname is not defined then it won't even do that.

Wild guess here but I think you are tryign to differentiate between one name or more and add and if its more than one....

If that is the case then you would have to explode $name and count the number of elements - but then someone might put a middle name in.

have a little think and come back with what you are trying to detect and maybe we can help a bit more.

Share this post


Link to post
Share on other sites

×

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.