The ArrayObjects class allows objects to work as arrays. The ArrayObjects::_construct() is an in built PHP function to construct a new array object.
Syntax:
public ArrayObject::__construct ($input = array(), int $flags = 0, string $iterator_class = "ArrayIterator")
Parameters: This function accepts three parameters as shown in the above syntax and are described below:
- $input: This parameter is used to accept input as an array or an object.
- $flags: Flags are used to control the behaviour of the Arrayobject.
- $iterator_class: It is used to specify the class that will be used for the iteration of the ArrayObject Object.
Return Value: This function returns an ArrayObject on successful compilation.
Errors and Exceptions:
- If $input is not an array or an object the compiler will show an error.
- If $flags set are not having integer values then the compiler will show an error message.
Below programs illustrate the ArrayObjects::_construct() function:
Program 1:
<?php $array = array('1' => 'one', '2' => 'two', '3' => 'three'); $arrayobject = new ArrayObject($array); var_dump($arrayobject); ?> |
Output:
object(ArrayObject)#1 (1) {
["storage":"ArrayObject":private]=>
array(3) {
[1]=>
string(3) "one"
[2]=>
string(3) "two"
[3]=>
string(5) "three"
}
}
Program 2:
<?php $array = array('1' => 'Geeks', '2' => 'for', '3' => 'Geeks'); $arrayobject = new ArrayObject($array); var_dump($arrayobject); ?> |
Output:
object(ArrayObject)#1 (1) {
["storage":"ArrayObject":private]=>
array(3) {
[1]=>
string(5) "Geeks"
[2]=>
string(3) "for"
[3]=>
string(5) "Geeks"
}
}
Reference:
http://php.net/manual/en/arrayobject.construct.php
Recommended Posts:
- How to get the function name inside a function in PHP ?
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | imagecreatetruecolor() Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- PHP | stream_get_transports() Function
- PHP | Ds\Deque pop() Function
- PHP | SimpleXMLElement children() Function
- PHP | array_intersect_ukey() Function
- PHP | is_numeric() Function
- PHP | Imagick adaptiveSharpenImage() Function
- PHP | XMLWriter endDtdEntity() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

