note 55311 added to function.array-keys

From: Date: Fri, 29 Jul 2005 22:43:16 +0000
Subject: note 55311 added to function.array-keys
Groups: php.notes 
Request: Send a blank email to php-notes+get-92743@lists.php.net to get a copy of this message
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 came up with my own solution. I didn't find the propiest function to post to so I will post it here, hope you find it useful. <?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 Have fun with it. ---- Submitter IP: 192.35.244.50 ---- Manual Page -- http://www.php.net/manual/en/function.array-keys.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55311 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55311&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55311&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55311&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55311&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55311&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55311&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55311&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92743) next »