unset

How does PHP's 'unset' construct work internally?

早过忘川 提交于 2019-11-30 09:14:40
问题 Preface: I do know how 'unset' works in the userland, but I would like to find out how it works internally. When unset is called on zval structure, it decreases the reference counter (refcount__gc). When refcount__gc reaches 0, the variable is no longer used and can be deleted. The question is whether it's always done immediately, or in some cases it can be done later by garbage collector? I have found two contradictory statements on this: unset() does just what it's name says - unset a

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

谁说胖子不能爱 提交于 2019-11-30 05:04:20
问题 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' ) [3563] => Array ( [0] => 12 [1] => 2014 [context] => 'aaa' ) [2421] => Array ( [0] => 5 [1] => 2014 [context] => 'zzz' ) ) I would like to remove every element with index '1' from subarrays. Desired output is: Array ( [3463] => Array ( [0] => 1 [context] => 'aaa' ) [3563] => Array ( [0] => 12 [context] => 'aaa

How does PHP's 'unset' construct work internally?

随声附和 提交于 2019-11-29 14:15:16
Preface: I do know how 'unset' works in the userland, but I would like to find out how it works internally. When unset is called on zval structure , it decreases the reference counter (refcount__gc). When refcount__gc reaches 0, the variable is no longer used and can be deleted. The question is whether it's always done immediately, or in some cases it can be done later by garbage collector? I have found two contradictory statements on this: unset() does just what it's name says - unset a variable. It does not force immediate memory freeing. PHP's garbage collector will do it when it see fits -

PHP Unset Array value effect on other indexes

独自空忆成欢 提交于 2019-11-28 11:55:53
I am working with a PHP loop, and I had one question regarding how unset affects the array keys. This array uses the standard numeric keys assigned by PHP, 0, 1, 2, 3 etc... . Whenever unset() runs on an array value, are the array keys shuffled or are they maintained as before? Thank you for your time. The keys are not shuffled or renumbered. The unset() key is simply removed and the others remain. $a = array(1,2,3,4,5); unset($a[2]); print_r($a); Array ( [0] => 1 [1] => 2 [3] => 4 [4] => 5 ) Test it yourself, but here's the output. php -r '$a=array("a","b","c"); print_r($a); unset($a[1]);

Unset an array element inside a foreach loop [duplicate]

懵懂的女人 提交于 2019-11-28 10:51:43
This question already has an answer here: How do you remove an array element in a foreach loop? 8 answers I'm accessing an array by reference inside a foreach loop, but the unset() function doesn't seem to be working: foreach ( $this->result['list'] as &$row ) { if ($this_row_is_boring) { unset($row); } } print_r($this->result['list']); // Includes rows I thought I unset Ideas? Thanks! You're unsetting the reference (breaking the reference). You'd need to unset based on a key: foreach ($this->result['list'] as $key => &$row) { if ($this_row_is_boring) { unset($this->result['list'][$key]); } }

Problems deleting cookies, won't unset

强颜欢笑 提交于 2019-11-28 09:00:38
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); But when I check the cookies in the cookies dialog in Firefox, it's still there with the same value. I set this cookie using the following line: setcookie("name", $value, time() + 259200, $path); I found this question on stackoverflow: , but none of the answers solved the problem. I also tried putting all paramaters in, like the author said, but it had no effect. Does anyone see the problem? The manual

Removing http headers in Apache2

南笙酒味 提交于 2019-11-27 16:49:31
问题 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 remvoe Server and Date: I have read the standard and I still want to do it. The bytes saved are significant (average response size is ~200B). In my site.conf (last load from apache2.conf) I have tried this with no success: Header unset Date Header

How do I delete an exported environment variable?

喜夏-厌秋 提交于 2019-11-27 09:55:29
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 environment variable. How can I achieve it? unset is the command you're looking for. unset GNUPLOT_DRIVER_DIR Walkthrough of creating and deleting an environment variable in bash: Test if the DUALCASE variable exists: el@apollo:~$ env | grep DUALCASE el@apollo:~$ It does not, so create the variable and export it: el@apollo:~$ DUALCASE=1 el@apollo:~$ export DUALCASE Check if it is there: el@apollo:~$ env |

Can you unset() many variables at once in PHP?

我怕爱的太早我们不能终老 提交于 2019-11-27 07:36:52
问题 I have a pretty high traffic social network site, I would like to get into the habit of unsetting large array and mysql object and even some string variables. So is it possible to unset more then 1 item in PHP example: <?PHP unset($var1); // could be like unset($var1,$var2,$var3); ?> 回答1: Yes. Your example will work just as you imagine. The method signature for unset() is as follows: void unset ( mixed $var [, mixed $var [, mixed $... ]] ) 回答2: The PHP manual can be very handy. You can search

Problems deleting cookies, won't unset

戏子无情 提交于 2019-11-27 02:33:52
问题 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); But when I check the cookies in the cookies dialog in Firefox, it's still there with the same value. I set this cookie using the following line: setcookie("name", $value, time() + 259200, $path); I found this question on stackoverflow: , but none of the answers solved the problem. I also tried putting all