|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-11-11 01:48 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 00:00:02 2025 UTC |
Description: ------------ Sorry if I did something wrong. This is my first time I submit a report. (Btw: when adding a note, the link "Click here to request a feature." redirects to bugs.php.net, is this correct?) I was looking for a function that deletes either integer keys or string keys (needed for my caching). As I didn't find a function I created a simple one. <?php function array_extract($array, $extract_type = 1) { foreach ( $array as $key => $value ) { if ( $extract_type == 1 && is_string($key) ) { // delete string keys unset($array[$key]); } elseif ( $extract_type == 2 && is_int($key) ) { // delete integer keys unset($array[$key]); } } return $array; } ?> You can of course define constants to have a nicer look, I have chosen these: EXTR_INT = 1; EXTR_STRING = 2 EXTR_INT will return an array where keys are only integer while EXTR_STRING will return an array where keys are only string I hope you find it useful.