note 38879 added to function.array-intersect

From: Date: Fri, 09 Jan 2004 18:11:35 +0000
Subject: note 38879 added to function.array-intersect
Groups: php.notes 
Request: Send a blank email to php-notes+get-63226@lists.php.net to get a copy of this message
This is also handy for testing an array for one of a series of acceptable elements. As a simple example, if you're expecting the query string to contain one of, say, user_id, order_id or item_id, to find out which one it is you could do this: $valid_ids = array ('user_id', 'item_id', 'order_id'); if ($id = current (array_intersect ($valid_ids, array_keys ($_GET)))) { // do some stuff with it } else // error - invalid id passed, or none at all ...which could be useful for constructing an SQL query, or some other situation where testing for them one by one might be too clumsy. ---- Manual Page -- http://www.php.net/manual/en/function.array-intersect.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38879 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38879&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38879&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#63226) next »