Page 1 of 1

array_search help in condition statement

Posted: Fri Sep 12, 2003 6:48 am
by JayBird
i have this code

Code: Select all

if (($key = array_search(date("z", mktime(0,0,0,9,$september,$year)), $days_off))) {
    // Do something
}
I have an Array called $days_off. This contains any numbers between 1 and 366, corresponding do what days people have got booked off work.

I am doing this array search against the number of the current day to see if anyone has a day of on this day.

The array_search returns the key of the Array where a match occurrs, but when the key is 0 the statment is false.

How can i can round this?

Mark

Posted: Fri Sep 12, 2003 7:17 am
by Judas
I should do it like this.
(didn't tested it :) )


$day=date("z", mktime(0,0,0,9,$september,$year));

if (in_array($day,$days_off)){
$key=array_search($day,$days_off);
}

Posted: Fri Sep 12, 2003 9:02 am
by JayBird
Yes, that is how i would do it :roll:

(from now-on anway :P )

Thanks