Skip to content

Instantly share code, notes, and snippets.

View veloxy's full-sized avatar
🤷‍♂️
What's happening?

Kevin Vandenborne veloxy

🤷‍♂️
What's happening?
View GitHub Profile
@veloxy
veloxy / gist:9134425
Created February 21, 2014 13:41
Create chunks of variable sizes
<?php
if (!function_exists('array_chunk_uneven')) {
function array_chunk_uneven(array $array, array $sizes)
{
while (list($key, $size) = each($sizes)) {
$chunks[] = array_slice($array, 0, $size);
$array = array_values(array_slice($array, $size, count($array)));
if ($array && $key == (count($sizes) - 1)) {
reset($sizes);
@veloxy
veloxy / gist:9134387
Last active August 29, 2015 13:56
String to array
<?php
function stringToArray($key)
{
$result = array();
$parts = explode('.', $key);
$current = &$result;
for ($i = 0, $max = count($parts); $i < $max; $i++) {
if (!isset($current[$parts[$i]])) {
$current[$parts[$i]] = array();
@veloxy
veloxy / Generate Combinations
Created November 8, 2011 20:07
Generate Combinations
<?php
function array_outer($f, array $array1) {
$res = array();
$arrays = $array1;
foreach ($arrays as $a) {
if (empty($a))
return $res;
}