Voting

: five plus two?
(Example: nine)

The Note You're Voting On

webmaster [at] baz-x [dot] at
19 years ago
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.

<< Back to user notes page

To Top