Skip to content

Instantly share code, notes, and snippets.

@iolloyd
Created August 24, 2015 19:02
Show Gist options
  • Save iolloyd/4598ceb45f8a17e69575 to your computer and use it in GitHub Desktop.
Save iolloyd/4598ceb45f8a17e69575 to your computer and use it in GitHub Desktop.
[a,b,c,d] => [a => b, c => d]
<?php
2
3 $array = ['one', 'two', 'three', 'four', 'five', 'six'];
4
5 $chunks = array_chunk($array, 2);
6 $firsts = array_map(function ($x) {return $x[0]; }, $chunks);
7 $seconds = array_map(function ($x){return $x[1]; }, $chunks);
8 $result = array_combine($firsts, $seconds);
9 print_r($result);
10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment