Jump to content

deleting multidimensional array


PC Nerd

Recommended Posts

unset deletes the variable.

 

So if you have a variable which is amultidimensional array. It will clear its contents and delete the variable.

 

example:

// a 2D arrary
$arr = array(
             'level1' => array(
                                'item1' => 'somevalue',
                                'item2' => 'somet8hing else',
                                'level2' => array(
                                                   'anotheritem' => 'foobar',
                                                   'somethingelse' => 'bar time'
                                                  )
                               )
             );

echo '<pre>' . print_r($arr, true) . '</pre>';

// unset $arr
unset($arr);

// test to see if $arr exists any more.
if(!isset($arr))
{
    echo 'variable $arr does not exist';
}
else
{
    echo 'variavle $arr exists!';
}

Link to comment
Share on other sites

but unset($Array) will delete the array, keys, values, even "if(!isset($Array))" wont run becauase its false

 

 

i wanted to check whether or not it completely delets its existence, or whether it simply emptis it

 

is there a function which simply empties a variable ( or an entore aray) or would i just loop through and reset to  ( "" )

 

 

thakx

Link to comment
Share on other sites

unset deletes the variable itself. That why in my code snippet I checked that $arr existed (after running unset). isset checks for variable existance not the variables value, and thus when you run the code you see the output of $arr but then you get a message saying $arr does not exist.

 

If only want to empty a variables value just set it again with an empty value, example

 

$arr = array(values here);

// remove $arr's value
$arr = null;

That will now clear $arr's value and not delete the variable.

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.