ArrayObject offsetSet () Function in PHP

PHP

Syntax :
void offsetSet ($index, $val)
Parameters : This function takes two parameters $index and $val. This function updates the value present in the index, $index with $val.Return value : This function does not return no value.The following programs illustrate the above function:Program 1 :
// PHP illustration program
// offsetSet() function $arr = array ( " engineer100 " , "engineer99" , "engineer1 " , " engineer02 " );  
// Create array object $arrObject = new ArrayObject ( $arr );  
// Update the value at index 1 $arrObject -> offsetSet (1, "Updated" );  
// Print the updated ArrayObject print_r ( $arrObject );  
?>
Exit:
ArrayObject Object ( [storage: ArrayObject: private] = > Array ([0] = > engineer100 [1] = > Updated [2] = > engineer1 [3] = > engineer02))
Program 2 :
// PHP -program for illustration
// offsetSet() function $arr = array ( "Welcome" = > "1 " , " to " = > "2" , "GfG" = > "3" );  
// Create array object $arrObject = new ArrayObject ( $arr );  
// Update the value by index "to" $arrObject -> offsetSet ( "to" , "UpdatedValue" );  
// Print the updated ArrayObject print_r ( $arrObject );  
?>
Exit:
ArrayObject Object ( [storage: ArrayObject: private] = > Array ([Welcome] = > 1 [to] = > UpdatedValue [GfG] = > 3))
Link: http://php.net/manual/en/arrayobject.offsetset.php