note 84628 deleted from function.in-array by danbrown

From: Date: Mon, 08 Jun 2009 21:39:56 +0000
Subject: note 84628 deleted from function.in-array by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-156496@lists.php.net to get a copy of this message
Note Submitter: bfpdevel at gmail dot com ---- @param mixed $key (string || array) <?php function inArray($array, $key) { if(func_num_args() == 2 && is_string($key)) return in_array($key, $array); else if(func_num_args() == 2 && is_array($key)) { $r = true; for($i=0; $i < count($key); $i++) $r = (!in_array($key[$i], $array)) ? false : $r; return $r; } else if(func_num_args > 2) { $args = func_get_args(); $r = true; for($i=1; $i < count($args); $i++) $r = (!in_array($args[$i], $array)) ? false : $r; return $r; } } /* EXAMPLES */ $array = array('a', 'b', 'c', 'd', 'e', 'f'); // Example 1 if(inArray($array, 'b')) echo 'b is in array'; // Example 2 if(inArray($array, array('b', 'a', 'e'))) echo 'a, b and e are in array'; // Example 3 if(inArray($array, 'b', 'a', 'e')) echo 'a, b and e are in array'; ?>

« previous php.notes (#156496) next »