Php Arrayiterator Example - Php

What is php arrayiterator?

Snippet Code


  
Rate this page :
  [ 0 votes]

Php arrayiterator which allows you to modify and unset the values while iterating over arrays and objects. Here, ArrayIterator::current which allows you to return the current array entries.

<?php $arr = array('1' => 'apple', '2' => 'banana', '3' => 'cherry'); $arrobj = new ArrayObject($arr); for($iterator = $arrobj->getIterator(); $iterator->valid(); $iterator->next()) { echo $iterator->key() . ' => ' . $iterator->current() . "</br>"; } ?>

Tags


Ask Questions

Ask Question