Hacker News new | ask | show | jobs
by kingdomcome50 2037 days ago
While not quite as ergonomic as your example, it's rather trivial to extend ArrayIterator to accomplish your goal:

    foreach ($iter = new IndexingIterator($array) as $k => $v) {
        echo $iter->index();
    }