Created
June 16, 2014 18:41
-
-
Save 0xMatt/3996cd73992957fec6e4 to your computer and use it in GitHub Desktop.
Iterate over indexed array and group evey two values into associative array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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