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!';
}

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

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.

Archived

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

×
×
  • 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.