ArrayObject offsetUnset() Function in PHP
Last Updated :
26 Mar, 2019
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
$arr = array ( "Welcome" => "1" , "to" => "2" , "GfG" => "3" );
$arrObject = new ArrayObject( $arr );
$arrObject ->offsetUnset( "to" );
print_r( $arrObject );
?>
|
Output:
ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[Welcome] => 1
[GfG] => 3
)
)
Program 2:
<?php
$arr = array ( "geeks100" , "geeks99" , "geeks1" , "geeks02" );
$arrObject = new ArrayObject( $arr );
$arrObject ->offsetUnset(1);
$arrObject ->offsetUnset(2);
print_r( $arrObject );
?>
|
Output:
ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[0] => geeks100
[3] => geeks02
)
)
Reference: http://php.net/manual/en/arrayobject.offsetunset.php
Share your thoughts in the comments
Please Login to comment...