Tuesday, November 18, 2025
HomeLanguagesPHP ArrayObject setFlags() Function

PHP ArrayObject setFlags() Function

The ArrayObject::setFlags() function is an inbuilt function in PHP that is used to set the flag to change the behavior of the ArrayObject. 

Syntax:

void ArrayObject::setFlags( int $flags )

Parameters: This function accepts single parameter $flags which hold the behavior of new ArrayObject. This parameter holds either a bitmask or named constants. 

Return Value: This function does not return any value. 

Below examples illustrate the ArrayObject::setFlags() function in PHP: 

Example 1: 

php




<?php 
// PHP program to illustrate the 
// ArrayObject::setFlags() function 
  
// Declare an array and convert
// it into array object
$arrObject = new ArrayObject(
    array('Geeks', 'for', 'Geeks')
); 
  
// Use ArrayObject::getFlags() function
// to get the behavior of flags
$flag = $arrObject->getFlags(); 
  
var_dump($flag); 
  
// Set a new flags
$arrObject->setFlags(ArrayObject::ARRAY_AS_PROPS);
  
// Use ArrayObject::getFlags() function
// to get the behavior of flags
$flag = $arrObject->getFlags(); 
  
var_dump($flag); 
  
?>


Output:

int(0)
int(2)

Example 2: 

php




<?php 
// PHP program to illustrate the 
// ArrayObject::setFlags() function 
  
// Declare an associative array
$arr = array(
    "a" => "Welcome",
    "b" => "to"
    "c" => "neveropen"
); 
  
// Create array object 
$arrObject = new ArrayObject($arr); 
  
// Use ArrayObject::getFlags() function
// to get the behavior of flags
$flag = $arrObject->getFlags(); 
  
var_dump($flag); 
  
// Set a new flags
$arrObject->setFlags(ArrayObject::STD_PROP_LIST);
  
// Use ArrayObject::getFlags() function
// to get the behavior of flags
$flag = $arrObject->getFlags(); 
  
var_dump($flag); 
  
?>


Output:

int(0)
int(1)

Reference: https://www.php.net/manual/en/arrayobject.setflags.php

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32402 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6773 POSTS0 COMMENTS
Nicole Veronica
11924 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11992 POSTS0 COMMENTS
Shaida Kate Naidoo
6900 POSTS0 COMMENTS
Ted Musemwa
7158 POSTS0 COMMENTS
Thapelo Manthata
6857 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS