CanMan2004 Posted September 18, 2006 Share Posted September 18, 2006 HiI 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 advanceDave Link to comment https://forums.phpfreaks.com/topic/21148-varible-using-if-statement/ Share on other sites More sharing options...
Hepp Posted September 18, 2006 Share Posted September 18, 2006 Try this:[code]$name = "Dave Lawson";if ($hisname >= '1') { print 's and '; } else { print 's'; }print $name;[/code] Link to comment https://forums.phpfreaks.com/topic/21148-varible-using-if-statement/#findComment-93936 Share on other sites More sharing options...
HuggieBear Posted September 18, 2006 Share Posted September 18, 2006 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...RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/21148-varible-using-if-statement/#findComment-93940 Share on other sites More sharing options...
ToonMariner Posted September 18, 2006 Share Posted September 18, 2006 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. Link to comment https://forums.phpfreaks.com/topic/21148-varible-using-if-statement/#findComment-93946 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.