Related Articles

Related Articles

PHP | ArrayObject setFlags() Function
  • Last Updated : 27 Sep, 2019

The ArrayObject::setFlags() function is an inbuilt function in PHP which 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 holds the behavior of new ArrayObject. This parameter holds either a bitmask or named constants.

Return Value: This function does not return any value.

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



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
// PHP program to illustrate the 
// ArrayObject::getFlags() 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); 
  
?>

chevron_right


Output:

int(0)
int(2)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
// PHP program to illustrate the 
// ArrayObject::getFlags() function 
  
// Declare an associative array
$arr = array(
    "a" => "Welcome",
    "b" => "to"
    "c" => "GeeksforGeeks"
); 
  
// 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); 
  
?>

chevron_right


Output:

int(0)
int(1)

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :