Re: Re: destroying objects in an array in PHP5
| From: | Matt M. | Date: | Tue, 27 Jul 2004 19:28:03 +0000 |
| Subject: | Re: Re: destroying objects in an array in PHP5 | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-192004@lists.php.net to get a copy of this message | ||
On Tue, 27 Jul 2004 21:22:05 +0200, Erik Franzén <erik@nordicaudi.com> wrote:
> I am correcting myself...
>
> <?PHP
> class foo {}
>
> $oObjectA = array();
> $oObjectB = array();
>
> for($i=0;$i<2;$i++) {
> $oObjectA[$i] = new foo();
> $oObjectB[$i] = $oObjectA[$i];
> }
>
> unset($oObjectA[1]);
>
> var_dump($oObjectA);
> var_dump($oObjectB);
> ?>
>
> will output:
>
> array(1) {
> [0]=>
> object(foo)#1 (0) {
> }
> }
> array(2) {
> [0]=>
> object(foo)#1 (0) {
> }
> [1]=>
> object(foo)#2 (0) {
> }
> }
>
> So my question is, how do I destroy the object $oObjectA[1] in both arrays?
you could try:
$oObjectB[$i] = &$oObjectA[$i];
or
unset($oObjectA[1],$oObjectB[1]);