Jump to content

[SOLVED] php function - Please help!


Roy Barten

Recommended Posts

Hello, i build the following function:

 

function ConvertToDateTime($number,$calendartype)
{
if ($calendartype == "week"){
$time = date("$number:00:00 2009-03-02");
$date = strtotime($time);
}
if ($calendartype == "month"){
echo "maand";
$day = date("00:00:00 2009-03-$number");
$date = strtotime($day);
}
}

 

Now the result of the following function is placed into $date. But into another function i need this result, so i have function calles function1. And function 1 calls function2 to convert an variable into a date, and then function1 has to continue and have to call function3 who also needs function2. How do i do this? Please help!

Link to comment
https://forums.phpfreaks.com/topic/145549-solved-php-function-please-help/
Share on other sites

Functions work best, when they return values

 

function ConvertToDateTime($number,$calendartype)
   {
if ($calendartype == "week"){
$time = date("$number:00:00 2009-03-02");
   $date = strtotime($time);
   }
if ($calendartype == "month"){
echo "maand";
   $day = date("00:00:00 2009-03-$number");
   $date = strtotime($day);
   }
return $date;
}

 

And then

 

<?php

$date = ConvertToDateTime(12,"week");
anotherfunction($date);
...

Here solution. I hope that this help you

 

function ConvertToDateTime($number,$calendartype)
   {
if ($calendartype == "week"){
$time = date("$number:00:00 2009-03-02");
   $date = strtotime($time);
   }
if ($calendartype == "month"){
echo "maand";
   $day = date("00:00:00 2009-03-$number");
   $date = strtotime($day);
   }
return  $date;

}


function function2 ()

{ $date= ConvertToDateTime($number,$calendartype);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.