Reputation: 625
I have the following code:
$search = '3,39,49,5,5,2012';
$search = mktime($search);
echo $search;
That just outputs the current timestamp, not the one for the date specified. However if I do the following:
$search = mktime(3,39,49,5,5,2012);
echo $search;
It outputs the correct timestamp, 1336203589. Any ideas?
Upvotes: 0
Views: 1698
Reputation: 489
mktime expects an array of time values, so you have just to split your array with explode
oder preg_split
$search = '3,39,49,5,5,2012';
$t = explode(',', $search);
$search = mktime($t[0], $t[1], $t[2], $t[3], $t[4], $t[5]);
Upvotes: 1
Reputation: 42642
Try this:
$search = '3,39,49,5,5,2012';
$search = call_user_func_array('mktime',explode(',', $search));
echo $search;
Demo: http://codepad.viper-7.com/lxTJbO
Upvotes: 4
Reputation: 7302
That is because you need to specify a list of integers to mktime
. You are passing a string
to it (which for your understanding is a list, but not so for the php interpretor). You need to convert it to such a list:
$search = '3,39,49,5,5,2012';
$search = mktime(explode(',', $search));
echo $search;
Upvotes: 1