runnerjp Posted December 1, 2008 Share Posted December 1, 2008 im trying to add my "get users age" code into a function but it displays nothing... any1 know where im going wrong? function function getage($dob) { $birthday = $pdob; $today = date('d-m-Y'); $a_birthday = explode('-', $birthday); $a_today = explode('-', $today); $day_birthday = $a_birthday[0]; $month_birthday = $a_birthday[1]; $year_birthday = $a_birthday[2]; $day_today = $a_today[0]; $month_today = $a_today[1]; $year_today = $a_today[2]; $age = $year_today - $year_birthday; if (($month_today < $month_birthday) || ($month_today == $month_birthday && $day_today < $day_birthday)) { $age--; } } the code on the page is $dob= $getuserprofile['dob']; he age is <?php getage($dob); echo $age?> Link to comment https://forums.phpfreaks.com/topic/134986-solved-getiing-age-through-function/ Share on other sites More sharing options...
GKWelding Posted December 1, 2008 Share Posted December 1, 2008 use $dob= $getuserprofile['dob']; he age is <?php $age=getage($dob); echo $age?> instead... Link to comment https://forums.phpfreaks.com/topic/134986-solved-getiing-age-through-function/#findComment-702991 Share on other sites More sharing options...
GKWelding Posted December 1, 2008 Share Posted December 1, 2008 also, your function needs to have a return in it, like below... function getage($dob) { $birthday = $pdob; $today = date('d-m-Y'); $a_birthday = explode('-', $birthday); $a_today = explode('-', $today); $day_birthday = $a_birthday[0]; $month_birthday = $a_birthday[1]; $year_birthday = $a_birthday[2]; $day_today = $a_today[0]; $month_today = $a_today[1]; $year_today = $a_today[2]; $age = $year_today - $year_birthday; if (($month_today < $month_birthday) || ($month_today == $month_birthday && $day_today < $day_birthday)) { $age--; } return $age; } Link to comment https://forums.phpfreaks.com/topic/134986-solved-getiing-age-through-function/#findComment-702992 Share on other sites More sharing options...
tapos Posted December 1, 2008 Share Posted December 1, 2008 Also one more thing $birthday = $pdob; should be $birthday = $dob; hope this will solve your problem Link to comment https://forums.phpfreaks.com/topic/134986-solved-getiing-age-through-function/#findComment-702996 Share on other sites More sharing options...
runnerjp Posted December 1, 2008 Author Share Posted December 1, 2008 ahh yes ty guys a typo there (with the p) and i didnt relise i needed to return age ... ty works great Link to comment https://forums.phpfreaks.com/topic/134986-solved-getiing-age-through-function/#findComment-702997 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.