note 76244 added to ref.array
| From: | Jason at osu1 dot php dot net | Date: | Sat, 07 Jul 2007 03:48:59 +0000 |
| Subject: | note 76244 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128277@lists.php.net to get a copy of this message | ||
<?php
/* Another version of subArr() function by simone dot
carletti at unimc dot it:
written for http://www.hendersonpoolservice.info
*/
//{{{ array_select()
/**
* Choose array element with given keys
*
* @param Array $arr
* @param Array $keys Keys/indexes of elements to choose
* @return Array Array with elements being references to the elements od original array
with chosen indexes.
*/
function &array_select($arr, $keys)
{
$res = array();
foreach ($keys as $key) {
if (array_key_exists($key, $arr)) {
$res[$key] =& $arr[$key];
}
}
return $res;
} // end: array_select() }}}
/*
In my opinion it should be faster than subArr().
Another difference from subArr() is that elements of returned array are references to the same
variables as elements of original array (this can be easily changed)
*/
?>
----
Server IP: 208.69.120.35
Probable Submitter: 68.96.96.27
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit -- https://master.php.net/note/edit/76244
Del: integrated -- https://master.php.net/note/delete/76244/integrated
Del: useless -- https://master.php.net/note/delete/76244/useless
Del: bad code -- https://master.php.net/note/delete/76244/bad+code
Del: spam -- https://master.php.net/note/delete/76244/spam
Del: non-english -- https://master.php.net/note/delete/76244/non-english
Del: in docs -- https://master.php.net/note/delete/76244/in+docs
Del: other reasons-- https://master.php.net/note/delete/76244
Reject -- https://master.php.net/note/reject/76244
Search -- https://master.php.net/manage/user-notes.php