PC Nerd Posted April 9, 2007 Share Posted April 9, 2007 if i have a multi dimentional array, eg: $arr[x][y] = ''; and i want to delete the enrite thing, does unset($arr); rowk, or so i have to delet the second arrays, or how do i do it??? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted April 9, 2007 Share Posted April 9, 2007 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!'; } Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 9, 2007 Author Share Posted April 9, 2007 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 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted April 9, 2007 Share Posted April 9, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.