php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #33926 Maybe a nice function for future releases
Submitted: 2005-07-30 01:52 UTC Modified: 2006-11-11 01:48 UTC
From: webmaster at baz-x dot at Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.3.11 OS: WinXP Home Edition Build 2600
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: webmaster at baz-x dot at
New email:
PHP Version: OS:

 

 [2005-07-30 01:52 UTC] webmaster at baz-x dot at
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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-11 01:48 UTC] tony2001@php.net
There is not much point to add functions to PHP which can be implemented in PHP itself in a couple of lines.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Sep 17 23:01:27 2024 UTC