unset Questions

27

Solved

Is there an easy way to delete an element from an array using PHP, such that foreach ($array) no longer includes that element? I thought that setting it to null would do it, but apparently it does...
Terpsichore asked 15/12, 2008 at 20:28

13

Solved

I have a global variable in JavaScript (actually a window property, but I don't think it matters) which was already populated by a previous script, but I don't want another script that will run lat...

7

Solved

Before installing gnuplot, I set the environment variable GNUPLOT_DRIVER_DIR = /home/gnuplot/build/src. During the installation, something went wrong. I want to remove the GNUPLOT_DRIVER_DIR enviro...
Heaps asked 29/7, 2011 at 18:58

11

Solved

I want to remove a key from a dictionary if it is present. I currently use this code: if key in my_dict: del my_dict[key] Without the if statement, the code will raise KeyError if the key is not ...
Gabriello asked 30/6, 2012 at 20:27

4

Solved

I am playing around with arrays in PHP, and I've get confused about unset() function, here's the code: <?php $array = array(1, 2, 3, 4); foreach ($array as $value) { $value + 10; } unset($val...
Enrich asked 6/11, 2017 at 0:21

16

Solved

How do I unset a readonly variable in Bash? $ readonly PI=3.14 $ unset PI bash: PI: readonly variable or is it not possible?
Nealy asked 1/7, 2013 at 3:30

3

Solved

I have a multidimensional array like this: [ [ 'id' => 1, 'name' => 'John', 'address' => 'Some address 1' 'city' => 'NY' ], [ 'id' => 2, 'name' => 'Jack', 'address' =&gt...
Astir asked 27/3, 2020 at 13:19

6

Solved

Not sure why this is occurring: Basically, I have an array that contains the following arrays, see var_dump: array(2) { [0]=> array(1) { [0]=> string(3) "ivr" } [1]=> array(1) { ...
Beattie asked 5/9, 2012 at 21:1

6

I have this array $output which looks like this: Array( [0] => Array( [0] => 1a [1] => 1b [2] => 1c ) [1] => Array( [0] => 2a [1] => 2b [2] => 2c ) [2] => Arra...
Grimalkin asked 31/8, 2011 at 16:44

5

Solved

Is it a requirement of good TCL code? What would happen if we don't use the "unset" keyword in a script? Any ill-effects I should know about? I'm inheriting some legacy code and the errors that co...
Contribute asked 25/2, 2010 at 5:42

3

Solved

Have any way to unset different variables using a one command? unset HTTP_PROXY unset HTTPS_PROXY unset FTP_PROXY unset ALL_PROXY unset NO_PROXY
Corwin asked 22/8, 2015 at 19:58

4

Solved

I am using simple php unset() function to remove and index of array but it's showing the following error: Parse error: syntax error, unexpected 'unset' (T_UNSET) Here is my erroneous code: echo $t...
Seigler asked 30/1, 2014 at 6:42

18

Solved

I've tried searching the php manual and internet on how to delete cookies and I've tried it the exact same way they all say: setcookie("name", '', 1); or setcookie("name", '', time()-3600); B...
Hein asked 18/5, 2010 at 10:32

6

Solved

I iterate through an array of objects and want to delete one of the objects based on it's 'id' property, but my code doesn't work. foreach($array as $element) { foreach($element as $key => $va...
Anarchist asked 21/2, 2010 at 2:51

4

Solved

Trying to unset automatically all variables in script. Have tried this way: echo '<br /> Variables in Script before unset(): <br />'; print_r(array_keys(get_defined_vars())); echo ...
Fructiferous asked 8/10, 2014 at 1:42

6

Solved

How do I overwrite (or unset and then set) an array? Seems like "array = new_array" doesn't work.
Mouser asked 12/10, 2009 at 16:47

7

I've made a class that acts like an file wrapper. When user call delete method, i want to unset the object (actually $this). Is there a way (workaround) to do that? The manual said no, there is no ...
Tarweed asked 13/10, 2010 at 12:45

7

Solved

How can I remove an element of an array, and reorder afterwards, without having an empty element in the array? <?php $c = array( 0=>12,1=>32 ); unset($c[0]); // will distort the array. ...
Chelate asked 31/1, 2010 at 19:14

10

Solved

If I want to remove the last element of an array, I can use either of these two code: array_pop($array); (the return value is not used) unset($array[count($array) -1]); Is there any performance...
Bordereau asked 30/7, 2013 at 12:39

7

Solved

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] ==...
Prefer asked 13/3, 2019 at 6:54

1

Solved

So basically I made this situation, the parent has the css all: unset. Then I notice when I use Safari(Version 12.1.1 (14607.2.6.1.1)) all the children of it color only can be effected by * block,...
Harumscarum asked 22/5, 2019 at 3:4

6

How I can destroy an const? I tried unset( KEY ), but not work. <?php define('KEY', 'value'); echo KEY; //output value unset( KEY ); //no work ?>
Coprology asked 23/6, 2012 at 3:20

3

Solved

I have an array $cars = array("Volvo", "BMW", "Toyota", "Mercedes"); I wanted to remove first element "Volvo" and i use this unset($cars[0]); Now i have an array like this: Array ( ...
Caudill asked 6/10, 2018 at 10:47

1

I have recently updated my Github password at work (corporate Github account). I had configured Git on one of my VM which is Windows 10. Not whenever I do git pull or git push it throws error...
Fivespot asked 18/6, 2018 at 23:10

1

Solved

EDIT: This has been confirmed to be a bug and will be fixed: https://lists.gnu.org/archive/html/bug-bash/2018-03/msg00055.html So I'm messing around with bash's indirection feature, namerefs. I ...
Reading asked 8/3, 2018 at 17:59

© 2022 - 2024 — McMap. All rights reserved.