Jump to content

Archived

This topic is now archived and is closed to further replies.

knowram

[SOLVED] simple array question

Recommended Posts

I know this is a stupid question. But I just can't seem to find that answer.

Given an array and a variable is there some way to delete that variable from the array no mater where it is located in that array?

I know there must be some easy function for this but I can't seem to find it.

thanks for the help.

Share this post


Link to post
Share on other sites
Use unset()
[a href=\"http://www.php.net/manual/en/function.unset.php\" target=\"_blank\"]http://www.php.net/manual/en/function.unset.php[/a]

Share this post


Link to post
Share on other sites
I did find that but I can't seem to figure out how to use it. This is what i am doing.

$x = array (testing, dog, cat, testing2);

$newx = unset($x['testing2']);

That dose not seem to do anything.

Share this post


Link to post
Share on other sites
[code]$x = array (testing, dog, cat, testing2);

print_r($x);

$k = array_search('testing2', $x);
unset($x[$k]);

print_r($x);[/code]

[code]// The first print_r
Array
(
    [0] => testing
    [1] => dog
    [2] => cat
    [3] => testing2
)

// Second print_r
Array
(
    [0] => testing
    [1] => dog
    [2] => cat
)[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.