note 84628 added to function.in-array

From: Date: Tue, 22 Jul 2008 17:58:40 +0000
Subject: note 84628 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-142512@lists.php.net to get a copy of this message
@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'; ?> ---- Server IP: 69.147.83.197 Probable Submitter: 190.135.174.54 ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- https://master.php.net/note/edit/84628 Del: integrated -- https://master.php.net/note/delete/84628/integrated Del: useless -- https://master.php.net/note/delete/84628/useless Del: bad code -- https://master.php.net/note/delete/84628/bad+code Del: spam -- https://master.php.net/note/delete/84628/spam Del: non-english -- https://master.php.net/note/delete/84628/non-english Del: in docs -- https://master.php.net/note/delete/84628/in+docs Del: other reasons-- https://master.php.net/note/delete/84628 Reject -- https://master.php.net/note/reject/84628 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#142512) next »