Jump to content

[SOLVED] can you use unset() on multidimentional arrays? it doesn't seem to work


Zaid

Recommended Posts

btw, im trying to use unset() from inside a method

 

 

class cookie(){

public $cookie_array_full;

 

function blahblah($key){

unset($GLOBALS['cookie_array_full[0][$key]']);

 

}

 

}

 

any idea why it doesn't work? :(

Link to comment
Share on other sites

That is invalid call to an array element:

$GLOBALS['cookie_array_full[0][$key]']

 

It should like this:

$GLOBALS['cookie_array_full'][0][$key]

 

still doesn't work :(

 

i got it to work but using a different syntax:

unset($this->cookie_array_full[0][$key]);

Link to comment
Share on other sites

What is the format of the $GLOBALS['cookie_array_full'] array?

 

To see the format of $GLOBALS['cookie_array_full'] array use print_r, example:

 

echo '<pre>' . print_r($GLOBALS['cookie_array_full'], true) . '</pre>';

 

Array
(
    [0] => Array
        (
            [0] => 3
            [1] => 65
        )

    [1] => Array
        (
        )

)

i've read that unset will work inside a function, but will only change it locally, even when the array is a global array

and therefore i should use $GLOBALS, but i guess it doesn't work

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.