Voting

: five plus zero?
(Example: nine)

The Note You're Voting On

anbolb at boltblue dot com
21 years ago
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:

<?php
$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.

<< Back to user notes page

To Top