VOOZH about

URL: https://www.geeksforgeeks.org/php/arrayobject-offsetset-function-in-php/

⇱ ArrayObject offsetSet() Function in PHP - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ArrayObject offsetSet() Function in PHP

Last Updated : 11 Jul, 2025
The offsetSet() function of the ArrayObject class in PHP is used to update the value present at a specific index in the ArrayObject. Syntax:
void offsetSet($index, $val) 
Parameters: This function accepts two parameters $index and $val. This function updates the value present at the index, $index with $val. Return Value: This function does not returns any value. Below programs illustrate the above function: Program 1:
Output:
ArrayObject Object
(
 [storage:ArrayObject:private] => Array
 (
 [0] => geeks100
 [1] => Updated
 [2] => geeks1
 [3] => geeks02
 )

)
Program 2:
Output:
ArrayObject Object
(
 [storage:ArrayObject:private] => Array
 (
 [Welcome] => 1
 [to] => UpdatedValue
 [GfG] => 3
 )

)
Reference: https://www.php.net/manual/en/arrayobject.offsetset.php
Comment