note 11764 added to array_slice
| From: | quix at stuff dot gen dot nz | Date: | Tue, 06 Mar 2001 12:29:04 +0000 |
| Subject: | note 11764 added to array_slice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-11931@lists.php.net to get a copy of this message | ||
It's a pity you can't do something like this:
$input = array ("a"=>"a string", "b"=>"b string",
"c"=>"c string", "d"=>"d string",
"e"=>"e string");
$get=array("a","e");
$out=array_slice($input,$get);
//to give you $out=array("a"=>"a string","e"=>"e
string")
like you can with hash slices in perl..
of course you could use preg_grep or a work around like:
function slice($arr,$keys) {
foreach ($keys as $k) {$tmp[$k]=$arr[k];}
return($tmp);
}
but that's bound to be slower..
http://www.php.net/manual/en/function.array-slice.php