Snippets

Array helpers #1

Just some random (relevance wise) functions for array manipulations. /** * Combines a new array using initial array even values * as keys and odd as their values * * @param array $initial * @param callable $key_callback Applied on keys * @param callable $value_callback Applied on values * @return array */ function arrayCombineFromValues( array $initial, callable $key_callback = null, callable $value_callback = null ) { $values = array_values($initial); $combined = array(); for ($i = 0; $i < count($values); $i += 2) { $key = $key_callback ? $key_callback($values[$i]) : $values[$i]; $val...