PHP 8.5.0 Alpha 4 available for testing

Voting

: five minus one?
(Example: nine)

The Note You're Voting On

Csaba at alum dot mit dot edu
19 years ago
Sometimes you may want to extract only a named subset of the key/value pairs in an array. This keeps things more orderly and could prevent an unrelated variable from getting clobbered from an errant key. For example,

$things = 'unsaid';
$REQUEST = array(He=>This, said=>1, my=>is, info=>2, had=>a,
very=>3, important=>test, things=>4);
$aVarToExtract = array(my, important, info);
extract (array_intersect_key ($REQUEST, array_flip($aVarToExtract)));

will extract
$my = 'is';
$important = 'test';
$info = 2;

but will leave certain
$things = 'unsaid'

Csaba Gabor from Vienna
NB. Of course the composite request coming in from a web page is in $_REQUEST.

<< Back to user notes page

To Top