Questions tagged [unset]

Removing the value associated with a variable or property from the current environment.

Common usages:

  • Destroying a variable or member of an array in PHP.
  • Removing the value bound to a property in Apache Ant.
  • Removing a variable from the environment of a shell script.
595 questions
3
votes
5 answers

PHP delete array index through value

I'm trying to unset two specific array positions which contain two values. My actual code to fill the array. function get_store_list(){ $data = @file_get_contents('http://www.zwinky.com/xml/clothingList.xml'); $data =…
pr0b
  • 377
  • 2
  • 3
  • 14
3
votes
3 answers

PHP - Remove an element from a stdclass array of stdclass objects

The heading might be a bit confusing because I'm not quite sure how to describe my 'array'. Here's how it looks when I use print_r... stdClass Object ( [0] => stdClass Object ( [Name] => Claude Bemrose [Skill] => 7 [Age]…
Farflame
  • 421
  • 1
  • 5
  • 17
3
votes
1 answer

How to delete or unset a cookie when the browser is closed?

I set following cookie when user open the site add_action('init', 'is_it_mobile_or_desktop', 1); function is_it_mobile_or_desktop(){ if (isset($_GET['site']) && in_array($_GET['site'], array('mobile', 'desktop'))){ setcookie(…
Foolish Coder
  • 385
  • 5
  • 20
3
votes
2 answers

Using unset() to delete node in XML; PHP/simplexml_load_file

I'm trying to use unset() to delete a node in an XML using PHP and can't figure out what is going on here. It doesn't seem to work correctly and I've seen a lot of other questions of similar nature on here but they don't seem to address this issue…
MillerMedia
  • 3,651
  • 17
  • 71
  • 150
3
votes
2 answers

Unsetting index in array turns it to an object

So I have a JSON document I'm storing in CouchDB. Here's the important part of it: "games": { "creator": [ "cf86d68b24c1bbf22702356572027642", "cf86d68b24c1bbf22702356572027dd8", "cf86d68b24c1bbf22702356572028b77" ], …
snollygolly
  • 1,858
  • 2
  • 17
  • 31
3
votes
2 answers

Chrome will not delete cookie?

I have a script that logs out the user (logout.php) and it works perfectly fine in FF and IE, but in Chrome the cookie is still available even after the browser has been closed. I have tested with this bit of…
Emily Adler
  • 51
  • 2
  • 4
3
votes
1 answer

How can I delete a property from a parent object in an extended class?

I am attempting to write a "listener" on a variable in a class I cannot modify. I am extending the class in question, unsetting the properties I want to listen to, and then using __set to intercept writes to that variable. At that point I compare…
epocsquadron
  • 303
  • 5
  • 9
3
votes
4 answers

unset session in smarty

After I insert data to database I will set a session and then redirect page to another page, on another page I will show a message if session was set in smarty, everything is ok. {if $smarty.session.insert===true} Thanks {/if} Now how can I…
MajAfy
  • 3,007
  • 10
  • 47
  • 83
3
votes
5 answers

Unset session when leaving page

How can I unset SESSION['variables'] when user is leaving a page, without having to include something on the top of every single page which I have on my site? Any best practises around you might know of? Thanks. EDIT I have a wizard for setting up a…
TMNuclear
  • 1,175
  • 5
  • 25
  • 49
3
votes
2 answers

PHP unset parts of a nested array

Trying to process an array and remove a specific associative array in a larger array set. The code I have now works in removing the specific sections locally, within the for loop, but doesn't effect the original $cursor array. foreach($cursor as…
alyx
  • 2,593
  • 6
  • 39
  • 64
3
votes
4 answers

Why unset() doesn't work in PHP ternary operator

So there is a problem with this, but i'm blind to it. Even after reading the documentation twice (PHP Comparison Operators) isset($items['blog']) ? unset($items['blog']) : NULL; Parse error: syntax error, unexpected T_UNSET
Merrick
  • 237
  • 3
  • 11
2
votes
2 answers

unset session variable halts execution

I have been going crazy over this piece of code and narrowed it down to the unset function. When I call unset on the session variable, PHP doesn't execute anything beyond that point. Can someone please help? public static function…
Randy Gonzalez
  • 445
  • 5
  • 17
2
votes
3 answers

Unset many array

I need help with my code. To unset xfer array from array below: if($_SESSION["s"]["user"]["typ"] == 'admin') { $form["tabs"]['dns_soa'] = array ( 'title' => "DNS Zone", 'width' => 100, 'template' =>…
sg552
  • 1,521
  • 6
  • 32
  • 59
2
votes
1 answer

wp_unregister_GLOBALS() in wordpress

The code below is from wordpress. Here are two things I don't understand: /** * Turn register globals off. * * @access private * @since 2.1.0 * @return null Will return null if register_globals PHP directive was disabled */ function…
steve
  • 608
  • 1
  • 5
  • 16