martin.kahil Posted November 14, 2007 Share Posted November 14, 2007 Hi, i'm new here and new to PHP. and i've read a large part of the PHP toturial, and have just one qustion.how do i write a function that returns a value. that i can do something like this below.. it actually works, but seems strange to me, and i'm sure the there is a better way to write it, were i declare that its a function that returns values.thankx! function days_in_month($month){if ($month==1 or $month==3 or $month==5 or $month==7 or $month==8 or $month==10 or $month==12) $monthlen=31;else if($month==4 or $month==6 or $month==9 or $month==11) $monthlen=30;else if(($year%4)==0) $monthlen=29;else $monthlen=28;return $monthlen;}$days=days_in_month(4); and the variable $days will be set to 30. Link to comment Share on other sites More sharing options...
Ingolme Posted November 14, 2007 Share Posted November 14, 2007 You can try this: function days_in_month($month,$year) {/* $year is necessary just in case it's a leap year */$d = mktime(0,0,0,1,$month,$year);//This function creates a PHP date object$days = date("t",$d);// 't' returns the days of a given monthreturn $days;}$days = days_in_month(4,2000); Link to comment Share on other sites More sharing options...
martin.kahil Posted November 16, 2007 Author Share Posted November 16, 2007 Thanks.. I figured out the $year thing alone.. but my question was someing else.. I want to to know if there is something in the function header that declares that its a function that returns a value or not...Like in Visual Basic Function days_in_month(month int, year int) int the last "int" says that its a function that returns an intenger. Is there something like it in PHP? Link to comment Share on other sites More sharing options...
Ingolme Posted November 16, 2007 Share Posted November 16, 2007 Just the return $days; line. If that line is present the function returns something, if not, nothing is returned. Link to comment Share on other sites More sharing options...
SpOrTsDuDe.Reese Posted November 16, 2007 Share Posted November 16, 2007 You can always use the echo statement. Link to comment Share on other sites More sharing options...
martin.kahil Posted November 17, 2007 Author Share Posted November 17, 2007 OK, Thanks everyone! Link to comment Share on other sites More sharing options...
martin.kahil Posted November 17, 2007 Author Share Posted November 17, 2007 Ingolme for your information, and everybody else:In the function mktime you write first the month then the day and in the end the year!witch means that it has to be like this: mktime(0,0,0,$month,1,$year);//this is rightmktime(0,0,0,1,$month,$year);//this is wrong! A litle difrence, but can drive you crazy untill you find it... Link to comment Share on other sites More sharing options...
Synook Posted November 18, 2007 Share Posted November 18, 2007 Hey what is wrong with American notation? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.