Syntax:public ArrayIterator::__ construct (mixed $array, int $flags = 0)
Parameters:This function takes two parameters as above and described below: - $array :This parameter contains an array or array of object iterators.
- $flag:This parameter contains a plane to control the behavior of the ArrayIterator.
Return value:this function returns an ArrayIterator object.The following programs illustrate the ArrayIterator::__ construct() function in PHP:Program 1: < tbody>
// Declare ArrayIterator
$arrItr
= new
ArrayIterator (
array
(
’G’
,
’e’
,
’ e’
,
’k’
,
’ s’
,
’f’
,
’o’
,
’ r’
),
ArrayIterator::ARRAY_AS_PROPS
);
// Show items
while
(
$arrItr
-> valid()) {
echo
$arrItr
-> current();
$arrItr
-> next();
}
?>
Exit:Geeksfor
Program 2:
// Declare ArrayIterator
$arrItr
=
new
ArrayIterator (
array
(
"Geeks"
,
"for"
,
" Geeks "
),
ArrayIterator::STD_PROP_LIST
);
// Show items
foreach
(
$arrItr
as
$key
= >
$val
) {
echo
$key
.
"= >"
.
$val
.
""
;
}
?>
Exit:0 = > Geeks 1 = > for 2 = > Geeks
Link: https://www.php.net /manual/en/arrayiterator.construct.php