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

PHP Unset object array elements in foreach loop without xpath

I need to unset all of the payment elements in the object so that only the payment elements that have johndoe as the Payee will be displayed. The code works partially. It unsets only the first payment element. xpath works for this example, but not…
Mike
  • 607
  • 8
  • 30
-1
votes
5 answers

Remove keys without specified names

I have an array like this: Array ( [44] => 2 [21] => 2 [] => 2 [27] => 2 ) How to find and remove (unset) keys without specified names? So in this case array should look like this: Array ( [44] => 2 [21] => 2 [27] =>…
dbx
  • 133
  • 18
-1
votes
1 answer

Completely Delete JSON-Object from JSON-Array

If i unset some Obkects in a JSON-Array via PHP, then i get an undefined Field with two empty []. But i want to delete the whole Object without []. This is the Code I am using: // Unset Data Object from…
danielx78
  • 41
  • 4
-1
votes
3 answers

How to remove a specific key from a multidimensional array

I want to remove a specific array key from all the inner arrays. I know there is a function called unset() which uses index or object name to slice it out. But I am not able to implement in my case in the below code. [answers] => Array …
topper1309
  • 151
  • 3
  • 16
-1
votes
4 answers

captcha works locally, but not on server!

I have a very annoying problem. I have a captcha system that work on my local network setup with xammp, but it does not work on my remote linux box. I have a teori that the captcha.php file reloads somehow, but I tried removing my google analytic…
ganjan
  • 7,356
  • 24
  • 82
  • 133
-1
votes
3 answers

Removing key from associative array

I would like to remove a certain value based on the value. Example in this situation, I would like to remove Tom from the array, then the next data will continue with the number that is previously used by Tom. Here's my example: $array =…
HelpNeeded
  • 33
  • 1
  • 1
  • 9
-1
votes
1 answer

PHP Unset $_POST on page refresh

I am trying to stop php from keeping my form submission but am having difficulties. Here is what I started with.
-1
votes
3 answers

PHP Remove empty value from array with unset not working correctly

I have a string containing sentences. I wish to break these sentences into an array, then modify each array item, including removing any array items that are empty. Here's what I have: //Explode string by dot $items_array = explode(".",…
MeltingDog
  • 14,310
  • 43
  • 165
  • 295
-1
votes
1 answer

Cannot unset session variable after echo

I have an error message stored in a session variable that I want to show only once. My method is to check if it's there, then echo it and unset it after.
-1
votes
3 answers

PHP unset() selectively working

I know there's a lot of these unset() problems on here, but this one is different. I'm trying to create an array that is a partial listing of a directory, with file names ".", "..", "feed.txt", and "index.php" removed. Here's the…
Ethan
  • 53
  • 1
  • 12
-1
votes
1 answer

How to delete array element by index

Is there any possible way to delete element from array? It is shopping cart storing item IDs. I want to make delete function. For example - cart_handler.php?delete=2687 array(5) { [1967]=> float(1) [1966]=> float(1) [2233]=> float(5) [2687]=>…
Zan Kravitz
  • 41
  • 1
  • 5
-1
votes
2 answers

unset a group of PHP sessions

I recently ran into a strange problem with PHP $_SESSION variables. On renewal-check.php we retreive a user's information from the database and save it like…
pattyd
  • 5,927
  • 11
  • 38
  • 57
-1
votes
1 answer

Notice: Undefined offset: 22 in C:\xampp\htdocs\authen.php on line 82

line numbber 82 is the if statement $re_arr is an array containing 25 elements if ($pass[0]==substr($re_arr[$i],0,1)) { $pass1[0]=$re_arr[$i]; unset($re_arr[$i]); $re_arr=array_values($re_arr); } what could be done to avoid the notice
Azra Mahrukh
  • 151
  • 1
  • 14
-1
votes
2 answers

Shorten code for removing array element with conditional in php pdo

Is there a way to shorten this code? It just seems clunky. Ive tried several shorthand ideas with ternary operators and couldnt get anything to work. So this is what I came up with. Any thoughts would be appreciated. $query =…
rprincejr
  • 67
  • 1
  • 8
-1
votes
2 answers

how to loop though an array and unset variables in the array

is there a way to loop through an array and unset any variables that are =""? i am looking for a faster way to do this aside form writing 4 if else statements.i thought this might work but i don't know if it can be done this way or…
sstokes
  • 3
  • 1