note 72822 added to ref.array
| From: | dkrysiak at o2 dot pl | Date: | Fri, 02 Feb 2007 08:40:09 +0000 |
| Subject: | note 72822 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-122533@lists.php.net to get a copy of this message | ||
// note: my previous post have one small error in call to array_key_exists() - posting again -
please remove this comment and that note :-)
<?php
/* Another version of subArr() function by simone dot carletti at unimc dot it: */
//{{{ 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: 195.136.184.34
Probable Submitter: 212.14.58.157
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit -- https://master.php.net/note/edit/72822
Del: integrated -- https://master.php.net/note/delete/72822/integrated
Del: useless -- https://master.php.net/note/delete/72822/useless
Del: bad code -- https://master.php.net/note/delete/72822/bad+code
Del: spam -- https://master.php.net/note/delete/72822/spam
Del: non-english -- https://master.php.net/note/delete/72822/non-english
Del: in docs -- https://master.php.net/note/delete/72822/in+docs
Del: other reasons-- https://master.php.net/note/delete/72822
Reject -- https://master.php.net/note/reject/72822
Search -- https://master.php.net/manage/user-notes.php