array_search help in condition statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

array_search help in condition statement

Post 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
Judas
Forum Commoner
Posts: 67
Joined: Tue Jun 10, 2003 3:34 pm
Location: Netherlands

Post 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);
}
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Yes, that is how i would do it :roll:

(from now-on anway :P )

Thanks
Post Reply