ArrayObject::offsetUnset

(no version information, might be only in CVS)

ArrayObject::offsetUnset --  Unsets the value at the specified $index

Description

void ArrayObject::offsetUnset ( mixed index )

警告

本函数暂无文档,仅有参数列表。


add a note add a note User Contributed Notes
primaryspace at hotmail dot com
01-Sep-2005 03:06
Removes an index from the array object, reducing the number of elements by one and condensing the list.

<?php

$ao
= new ArrayObject(array(1, 2, 3));

foreach(
$ao->getIterator() as $item) {
   if (
$item == 2) {
      
$ao->offsetUnset($ao->getIterator()->current());
   }
}

echo
$ao->count(); // Prints 2

?>

---
Note from the extension author:

Try this:

<?php

$ao
= new ArrayObject(array(1, 2, 3));

foreach(
$ao as $key=>$item) {  // getIterator() called automatically
  
if ($item == 2) {
      
$ao->offsetUnset($key);
   }
}

echo
$ao->count(); // Prints 2

?>