PHP Doku:: Unsets the value at the specified $index - splfixedarray.offsetunset.html

Verlauf / Chronik / History: (3) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzSonstige GrunderweiterungenStandard PHP Library (SPL)DatenstrukturenThe SplFixedArray classSplFixedArray::offsetUnset

Ein Service von Reinhard Neidl - Webprogrammierung.

The SplFixedArray class

<<SplFixedArray::offsetSet

SplFixedArray::rewind>>

SplFixedArray::offsetUnset

(PHP 5 >= 5.3.0)

SplFixedArray::offsetUnsetUnsets the value at the specified $index

Beschreibung

public void SplFixedArray::offsetUnset ( int $index )

Unsets the value at the specified index.

Parameter-Liste

index

The index being unset.

Rückgabewerte

Es wird kein Wert zurückgegeben.


Ein BenutzerBeitrag:
- Beiträge aktualisieren...
c dot 1 at smithies dot org
22.11.2010 17:07
This function assigns NULL to the array element. Its use has no effect on count(). Whereas assigning NULL to an element will have no effect on isset(), offsetUnset() and unset() do. Whereas unsetting an element affects the behaviour of foreach() as applied to an array or an ArrayObject, it has no such effect on SplFixedArray, as demonstrated by the code below.

<?php

class atest extends SplFixedArray {
  public function
fill() {
    for (
$i = $this->count(); --$i >= 0; ) $this[$i] = $i;
  }
  public function
dump() {
   
$sep = ' ';
    foreach (
$this as $k => $v) {
      echo
$sep, "$k: ", (is_null($v) ? 'NULL' : $v);
      if (!isset(
$this[$k])) echo ' and unset';
     
$sep = ', ';
    }
    echo
PHP_EOL;
  }
}

$a = new atest(3);
$a->dump(); //  0: NULL and unset, 1: NULL and unset, 2: NULL and unset
$a->fill();
$a->dump(); //  0: 0, 1: 1, 2: 2
$a[1] = NULL;
unset(
$a[2]);
$a->dump(); //  0: 0, 1: NULL, 2: NULL and unset
?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)