Skip to content

Instantly share code, notes, and snippets.

@ronan-gloo
Created May 26, 2013 17:51
Show Gist options
  • Select an option

  • Save ronan-gloo/5653498 to your computer and use it in GitHub Desktop.

Select an option

Save ronan-gloo/5653498 to your computer and use it in GitHub Desktop.
Convert non-associative array to associative array
<?php
$segments = ['one', 'two', 'three'];
$copy = $segments;
$assoc = [];
foreach ($segments as $key => $seg)
{
$segment = next($copy);
if (! ($key % 2))
{
$assoc[$seg] = $segment;
}
}
// outputs ['one' => 'two', 'three' => false];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment