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
9
votes
3 answers

Using string path to delete element from array

I have array like that $arr = [ 'baz' => [ 'foo' => [ 'boo' => 'whatever' ] ] ]; Is there anyway to unset ['boo'] value using string input? Something like that $str = 'baz->foo->boo'; function array_unset($str,…
remtsoy
  • 465
  • 1
  • 3
  • 15
8
votes
7 answers

PHP: unset from array using if statement

I'm trying to unset specific values using if statement. My code is $fruits = ['apple', 'orange', 'melon', 'banana', 'pineapple']; for ($i = 0 ; $i < count($fruits); $i++){ if ($fruits[$i] == 'apple' || $fruits[$i] == 'orange' || $fruits[$i] ==…
Kiki
  • 333
  • 2
  • 12
8
votes
4 answers

Why do I need unset $value after foreach loop

I am playing around with arrays in PHP, and I've get confused about unset() function, here's the code: Is it necessary to…
kronberger
  • 85
  • 1
  • 4
8
votes
1 answer

Removing http headers in Apache2

On an Apache2.2.9 hosted site, I would like to remove the headers below. Date Thu, 16 Dec 2010 17:49:45 GMT Server Apache Keep-Alive timeout=15, max=92 Connection Keep-Alive Let me preempt the discussion on whether or not it it right/legal/nice to…
michael
  • 81
  • 1
  • 1
  • 3
8
votes
4 answers

PHP: remove element from multidimensional array (by key) using foreach

I got multidimensional array. From each subarray, I would like to remove / unset values with index 1. My array $data. Array ( [3463] => Array ( [0] => 1 [1] => 2014 [context] => 'aaa' ) …
suz
  • 737
  • 2
  • 9
  • 22
8
votes
2 answers

Rearrange array index Eloquent Laravel

I have an error after delete an element from an array of laravel eloquent A property has rooms foreach ($property->rooms as $key => $room) { if ($room->type == 1 and $type ==1 and $room->price < $price->min or $room->price > $price->max) { …
Miguel
  • 1,577
  • 2
  • 15
  • 29
8
votes
6 answers

Javascript unset array

How do i unset an array in javascript? i just want to empty it - so it has nothing in it keys or anything
Richard Peers
  • 1,131
  • 3
  • 9
  • 7
8
votes
6 answers

Unsetting a variable vs setting to ''

Is it better form to do one of the following? If not, is one of them faster than the other? unset($variable); or to do $variable = '';
waiwai933
  • 14,133
  • 21
  • 62
  • 86
7
votes
2 answers

unset bash function variable with non-standard name

I may have this function in a bash script that gets sourced to the shell function suman{ echo "using suman function" } if I call unset suman things seem to work as expected however if I have this as my function: function suman-inspect { …
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
7
votes
3 answers

Remove element from bash array by content (stored in variable) without leaving a blank slot

I have an array list in a bash script, and a variable var. I know that $var appears in ${list[@]}, but have no easy way of determining its index. I'd like to remove it from list. This answer achieves something very close to what I need, except that…
Jonathan Y.
  • 526
  • 1
  • 5
  • 13
7
votes
1 answer

How to reset all environment variables?

I want to do : env | egrep -o '^\w+=' | unset The problem is that : env | egrep -o '^\w+=' prints things like (notice the equal sign) : XDG_VTNR= LC_PAPER= SSH_AGENT_PID= KDE_MULTIHEAD= LC_ADDRESS= XDG_SESSION_ID= How do I extract just…
Belun
  • 4,151
  • 7
  • 34
  • 51
7
votes
2 answers

Why does PHP's garbage collector slow down performance, and how to manage memory without it?

This relates to a PHP 5.3 Cli application that processes a lot of data in a complex way, taking hours to run. Someone discovered that turning off garbage collection made it run a great deal faster (maybe as much as 50%). The only article I've come…
naomi
  • 1,934
  • 1
  • 14
  • 29
7
votes
2 answers

How to delete an exact element in a bash array?

I am trying to remove just the first appearance of any one keyword from a bash array. ARRAY=(foo bar and any number of keywords) keywords=(red, rednet, rd3.0) I remove the keyword like this: ARRAY=( ${ARRAY[@]/"$keyword"/} ) then if "red' is the…
mateor
  • 1,293
  • 1
  • 16
  • 19
7
votes
2 answers

Reopened: PHP array_shift(); VS reset(); unset(); array_splice();

Reopened: Since PHP is a server-side language I had the assumption that it didn't matter what browser I used, but apparently not so. I had only been using Google Chrome. I installed WAMP on my local machine so I can test it locally to see if it did…
Jeff Reeves
  • 81
  • 1
  • 8
6
votes
1 answer

MongoDB : Update Modifier semantics of "$unset"

In MongoDB, the update modifier unset works as follows: Consider a Mongo DB Database db with a collection users. Users contain a Document, of the following format: //Document for a user with username: joe { "_id" :…
brud
  • 173
  • 2
  • 13
1 2
3
39 40