ecabrera Posted May 28, 2012 Share Posted May 28, 2012 can i echo inside a function i try to do it but doesnt work maybe i did it wrong for example month is a function it takes 3 parameter. birthdate_month has a number value from 1 - 12 inside the function im using switch so if birthdate_month is 1 do this if its 2 do that and so on but the function doesnt know what number is in birthdate_month only if i put a number like this month(1,$birthdate_day,$birthdate_year); if i do this it works but i dont want to do this i want it to fo it automaticly without me puting a number so is there a way to echo inside a function maybe like this but i try and doesnt work month(echo $birthdate_month;,$birthdate_day,$birthdate_year); Quote Link to comment https://forums.phpfreaks.com/topic/263245-echo-inside-a-function/ Share on other sites More sharing options...
manohoo Posted May 28, 2012 Share Posted May 28, 2012 there's no need to echo when calling the function, try this: month($birthdate_month, $birthdate_day, $birthdate_year); Quote Link to comment https://forums.phpfreaks.com/topic/263245-echo-inside-a-function/#findComment-1349117 Share on other sites More sharing options...
ecabrera Posted May 28, 2012 Author Share Posted May 28, 2012 nope heres the function just gives me Born on <?php function month($birthdate_month,$birthdate_day,$birthdate_year){ switch ($birthdate_month) { case 1: echo "January $birthdate_day, $birthdate_year"; break; case 2: echo "Febuary $birthdate_day, $birthdate_year"; break; case 3: echo "March $birthdate_day, $birthdate_year"; break; case 4: echo "April $birthdate_day, $birthdate_year"; break; case 5: echo "May $birthdate_day, $birthdate_year"; break; case 6: echo "June $birthdate_day, $birthdate_year"; break; case 7: echo "July $birthdate_day, $birthdate_year"; break; case 8: echo "August $birthdate_day, $birthdate_year"; break; case 9: echo "September $birthdate_day, $birthdate_year"; break; case 10: echo "October $birthdate_day, $birthdate_year"; break; case 12: echo "November $birthdate_day, $birthdate_year"; break; case 12: echo "December $birthdate_day, $birthdate_year"; break; default: echo ""; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/263245-echo-inside-a-function/#findComment-1349120 Share on other sites More sharing options...
ecabrera Posted May 28, 2012 Author Share Posted May 28, 2012 any one knoew id i can echo out the $month another way Quote Link to comment https://forums.phpfreaks.com/topic/263245-echo-inside-a-function/#findComment-1349127 Share on other sites More sharing options...
KevinM1 Posted May 28, 2012 Share Posted May 28, 2012 Why don't you want to put the month number as the first argument to your function? What do you mean by wanting to make it more automatic than that? Quote Link to comment https://forums.phpfreaks.com/topic/263245-echo-inside-a-function/#findComment-1349200 Share on other sites More sharing options...
scootstah Posted May 28, 2012 Share Posted May 28, 2012 You are way over-complicating the problem. function month($month, $day, $year) { echo date('F', mktime(0,0,0, $month, $day, $year)) . " $day, $year"; } Quote Link to comment https://forums.phpfreaks.com/topic/263245-echo-inside-a-function/#findComment-1349202 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.