The offsetUnset() function of the ArrayObject class in PHP is used to unset the value preset at a specific index. In other words, it is used to remove a value present at a specific index in the ArrayObject.
Syntax:
void offsetUnset($index)
Parameters: This function accepts a single parameter $index which is the index whose value is to be unset.
Return Value: This function does not returns any value.
Below programs illustrate the above function:
Program 1:
<?php // PHP program to illustrate the // offsetUnset() function $arr = array("Welcome"=>"1", "to" => "2", "GfG" => "3"); // Create array object $arrObject = new ArrayObject($arr); // Unset the value at index "to" $arrObject->offsetUnset("to"); // Print the updated ArrayObject print_r($arrObject); ?> |
ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[Welcome] => 1
[GfG] => 3
)
)
Program 2:
<?php // PHP program to illustrate the // offsetUnset() function $arr = array("geeks100", "geeks99", "geeks1", "geeks02"); // Create array object $arrObject = new ArrayObject($arr); // Unset the value at index 1 $arrObject->offsetUnset(1); // Unset the value at index 1 $arrObject->offsetUnset(2); // Print the updated ArrayObject print_r($arrObject); ?> |
ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[0] => geeks100
[3] => geeks02
)
)
Reference: http://php.net/manual/en/arrayobject.offsetunset.php
Recommended Posts:
- PHP | SplDoublyLinkedList offsetUnset() Function
- PHP | SplObjectStorage offsetUnset() Function
- PHP | SplFixedArray offsetUnset () Function
- PHP | ArrayIterator offsetUnset() Function
- ArrayObject uksort() Function in PHP
- ArrayObject append() function in PHP
- ArrayObject asort() Function in PHP
- ArrayObject exchangeArray() function in PHP
- ArrayObject getArrayCopy() Function in PHP
- ArrayObject getIterator() Function in PHP
- ArrayObject offsetExists() Function in PHP
- ArrayObject natsort() Function in PHP
- ArrayObject natcasesort() Function in PHP
- ArrayObject ksort() Function in PHP
- ArrayObject getIteratorClass() Function in PHP
- ArrayObject offsetGet() Function in PHP
- ArrayObject offsetSet() Function in PHP
- ArrayObject uasort() Function in PHP
- PHP | ArrayObject setFlags() Function
- PHP | ArrayObject serialize() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

