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
4
votes
1 answer

What is the point of unsetting the cookie during a logout from a php session?

I am developing a web application with PHP where a user will be able to have his or her own account, and the session that keeps track of the user is stored in a MySQL database. Now, after searching for an answer on how to implement this, I find that…
Muuse
  • 177
  • 1
  • 1
  • 9
4
votes
6 answers

Using unset() function in an array to delete elements

Trying to delete all elements in the array (given below) which are less then 0 using the following code:
Sam
  • 41
  • 1
4
votes
1 answer

unset() not working inside class methods

I have a class say, Foo that has a json string property named bar: [PHP Fiddle Link]
tika
  • 7,135
  • 3
  • 51
  • 82
4
votes
2 answers

Why does unset() change the way json_encode formats the string?

I noticed something interesting today using unset() and json_decode/json_encode. Here is the code: echo "

1) array as string

"; $sa = '["item1","item2","item3"]'; var_dump($sa); echo "

2) array as string decoded

"; $sad =…
Jason Spick
  • 6,028
  • 13
  • 40
  • 59
4
votes
2 answers

unset range of keys in an array

How can i unset a range of keys between say 70 to 80 in an array like this? [63] => Computer Science and Informatics [64] => Dentistry [65] => Development Studies [66] => Drama, Dance and Performing Arts [67] => Earth Systems and Environmental…
smith
  • 41
  • 1
  • 2
4
votes
2 answers

When I use error? and try, err need a value

Here my function that execute cmd as a Rebol instructions : exec-cmd: func [ cmd [ block! ] "Rebol instructions" /local err ] [ if error? err: try [ do cmd ] [ print mold disarm err ] ] When I launch…
gwailo59
  • 110
  • 6
4
votes
3 answers

Unset all instances of an object PHP

I have a class with a method that returns a new instance of itself. This allows me to use one single object without having to declare new ones over and over with the same values. For those wondering why not extending the class or something else, it…
multimediaxp
  • 9,348
  • 13
  • 49
  • 80
4
votes
6 answers

Overwrite array in JavaScript

How do I overwrite (or unset and then set) an array? Seems like "array = new_array" doesn't work.
Ivar
  • 4,344
  • 6
  • 38
  • 53
4
votes
3 answers

PHP $_SESSION variable will not unset

sorry for a repetitive question, I've seen a few of these on this forum but none of the responses worked for me... I am building a basic login using php sessions, which I'm new at... login.php validates html login form and begins a session, setting…
B Rad C
  • 510
  • 2
  • 6
  • 18
4
votes
2 answers

Recursive search and remove in array?

I am working with a multidimensional array I want to be able to remove an array (and all children) which match an id. The function I have tried is: function removeKey($key, $array, $childKey = 'children'){ if(isset($array[$key])){ …
Hailwood
  • 89,623
  • 107
  • 270
  • 423
3
votes
6 answers

$data = array() vs unset($array)

this is my first question. I am doing some optimizations on a php script, improving its speed of execution... Between : $datas = array(); $datas['file_import'] = $file_name_reporting; And : unset($datas); $datas['file_import'] =…
3
votes
4 answers

Partially delete/destroy $_SESSION data? PHP

I am looking for a way to delete only certain amounts of SESSION data that is stored whilst preserving the session data associated with the user being logged on. At the moment I am doing this by individual unset statements to the SESSION variables I…
tomaytotomato
  • 3,788
  • 16
  • 64
  • 119
3
votes
3 answers

jQuery: best practice for unsetting / removing function events?

I'm using the jQuery plugin Cloud Zoom, and I've altered the initialization so that the image is zoomed when the user clicks on a "magnify button" instead of hovering. I'm not sure how to unset/remove this event when the user leaves the image…
Staffan Estberg
  • 6,795
  • 16
  • 71
  • 107
3
votes
8 answers

Unset all defined variables from the current function

For example, I have this function: function foo($whaaaat){ $var1 = 'a'; $a = 1; $b = 2; ... // here unset all variables defined above (including arguments) require 'somefile.php'; } So, can I unset all those variables before the…
Alex
  • 66,732
  • 177
  • 439
  • 641
3
votes
1 answer

Strange behavior of `unset` for local variables

I can't explain the following behavior of unset: #!/bin/bash my_unset() { unset "$@"; } fn1() { local var; unset var; var=1; } fn2() { local var; my_unset var; var=2; } var=0 fn1; echo "$var" fn2; echo "$var" 0 2 edit: I would expect the…
Fravadona
  • 13,917
  • 1
  • 23
  • 35