[pmwiki-users] Avoiding the in_array() PHP built-in function

H. Fox haganfox at users.sourceforge.net
Wed Mar 29 21:09:12 CST 2006


On 3/29/06, Patrick R. Michaud <pmichaud at pobox.com> wrote:
> On Wed, Mar 29, 2006 at 07:15:46PM -0700, H. Fox wrote:
> > What is a better way of doing the following:
> >
> >   $Actions_allowed =
> >     array('browse','print','search','edit','login', 'rss', 'atom');
> >   if (! in_array($action, $Actions_allowed)) { # Do something. }
>
> I tend to use things like:
>
>     $Actions_allowed = array(
>       'browse' => 1, 'print' => 1, 'search' => 1, 'edit' => 1,
>       'login' => 1, 'rss' => 1, 'atom' => 1);
>     if (!@$Actions_allowed[$action]) { # Do something }

or even

    if (!array_key_exists($action)) { # Do something }

So obvious now.  :-)  Thanks!

Hagan




More information about the pmwiki-users mailing list