Skip to content

Instantly share code, notes, and snippets.

@0xMatt
Created June 16, 2014 18:41
Show Gist options
  • Save 0xMatt/3996cd73992957fec6e4 to your computer and use it in GitHub Desktop.
Save 0xMatt/3996cd73992957fec6e4 to your computer and use it in GitHub Desktop.
Iterate over indexed array and group evey two values into associative array
<?php
$array = ['string1', 'string2', 'string3'];
$obj = new ArrayObject( $array );
$it = $obj->getIterator();
$new = [];
while($it->valid())
{
if(!isset($new[$it->current()]))
{
$new[$it->current()] = '';
$holdCurrent = $it->current();
$it->next();
$new[$holdCurrent] = $it->current();
$it->next();
}
}
var_dump($new);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment