brown2005 Posted November 30, 2006 Share Posted November 30, 2006 <?phpfunction my($word1, $word2){ $word1 = $word1; $word2 = $word2; return "$word1 - $word2";}$word1 = "CABBAGE";$word2 = "APPLES";my($word1,$word2);?>hi, i was wondering if someone could help with this code.. to get it to work please.. Link to comment https://forums.phpfreaks.com/topic/29015-help-with-a-function-please/ Share on other sites More sharing options...
bljepp69 Posted November 30, 2006 Share Posted November 30, 2006 Your function returns "$word1 - $word2", but your function call didn't give it anything to return that value into.[code]$var = my($word1,$word2);[/code] Link to comment https://forums.phpfreaks.com/topic/29015-help-with-a-function-please/#findComment-132950 Share on other sites More sharing options...
craygo Posted November 30, 2006 Share Posted November 30, 2006 You have to echo the function if you are just returning a value in the functionThis[code]<?phpfunction my($word1, $word2){return "$word1 - $word2";}$word1 = "CABBAGE";$word2 = "APPLES";echo my($word1,$word2);?>[/code]Works just like this[code]<?phpfunction my($word1, $word2){echo "$word1 - $word2";}$word1 = "CABBAGE";$word2 = "APPLES";my($word1,$word2);?>[/code]Also your parameters to not have to be $word1 and $word2[code]<?phpfunction my($word1, $word2){echo "$word1 - $word2";}$field1 = "CABBAGE";$field2 = "APPLES";my($field1,$field2);?>[/code]The $word1 and $word2 are use by the function. when you call the function those 2 parameters are automatically applied to $word1 and $word2.Ray Link to comment https://forums.phpfreaks.com/topic/29015-help-with-a-function-please/#findComment-132951 Share on other sites More sharing options...
brown2005 Posted November 30, 2006 Author Share Posted November 30, 2006 cheers ray, exactly what i wanted... thanks everyone for the help.. Link to comment https://forums.phpfreaks.com/topic/29015-help-with-a-function-please/#findComment-132960 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.